Preben Alsholm

13743 Reputation

22 Badges

20 years, 330 days

MaplePrimes Activity


These are replies submitted by Preben Alsholm

There is still an rtable inside the procedure that you want to translate.

And also convert is not recognized:

doesnotworkeither := proc(p) convert(p,string) end proc;

CodeGeneration[C](doesnotworkeither);
Warning, the function names {convert} are not recognized in the target language
double doesnotworkeither (double p)
{
  return(convert(p, string));
}

There is still an rtable inside the procedure that you want to translate.

And also convert is not recognized:

doesnotworkeither := proc(p) convert(p,string) end proc;

CodeGeneration[C](doesnotworkeither);
Warning, the function names {convert} are not recognized in the target language
double doesnotworkeither (double p)
{
  return(convert(p, string));
}

@Joe Riel My last solution doesn't cover cases like

aa:=a:
plot(aa*sin(x),x=0..b) assuming a=-2, b=7;

which clearly is not acceptable.

So I returned to the first version handling temporary assignments by actually assigning the parameters before evaluating the first argument to `assuming`.

However, for the first version to handle vectors and matrices  op(eval(res,par)) in the last line before 'end proc' replaces op(eval(res)). The eval was inserted to get procedural output (e.g. from dsolve/numeric) evaluated.

Probably more problems will turn up.

p:=subsop(3=overload,eval(`assuming`)):
`assuming`:=overload(
       [
          proc(x::uneval,par1::list({equation,set(equation),list(equation)})) option overload;
           local par,res;
           par:=ListTools:-Flatten(evalindets(par1,set,[op]));
           assign(par);
           try
            res:=eval(x);
           catch:
            error;
           finally  
            map(unassign@lhs,eval(par,2));
           end try;
           op(eval(res,par))
          end proc,
          eval(p)
        ]
):

@Joe Riel The following doesn't split mixed assumptions and temporary assignments, but does handle both classes.

restart;
p:=subsop(3=overload,eval(`assuming`)):
`assuming`:=overload(
     [
        proc(x::uneval,a::list({equation,set(equation),list(equation)}),$) option overload;
            op(eval(x,ListTools:-Flatten(evalindets([a], set, [op]))));
        end proc,
        eval(p)
      ]
):
plot(a*sin(x),x=0..b) assuming {a=-2,b=7};
param := {a=2,b=7}:
plot(a*sin(x),x=0..b) assuming param;
plot(a*sin(x),x=0..b) assuming a=-2,b=7;
plot(a*sin(x),x=0..b) assuming [a=-2],{b=Pi};
simplify(sqrt((x*y)^2)) assuming x>0,y>0;
int(exp(a*t),t=0..infinity) assuming a<0;

#Interestingly, this one works (with or without overloading), but in the result b is not replaced by 2:

int(exp(b*a*t),t=0..infinity) assuming b=2,a<0;

#This one doesn't work, because the main procedure doesn't accept sets or lists of properties.

int(exp(b*a*t),t=0..infinity) assuming {a<0,b=2};

@acer You are right. 'Using' sounds better.

And I have to get used to using the 'use' statement. I had almost forgotten its existence.

Unfortunately, with

param:={a=-2,b=7};

neither one of
use param in plot(a*sin(x),x=0..b) end use;
use op(param) in plot(a*sin(x),x=0..b) end use;

works. It is convenient to have the parameters defined as a set or list since 'eval' doesn't accept a sequence, as does subs.

@pchin Thanks to Joe Riel and pchin. The wikipedia link about reentrancy is difficult reading, by I think I got the gist of it.

@pchin Thanks to Joe Riel and pchin. The wikipedia link about reentrancy is difficult reading, by I think I got the gist of it.

@pvrbik I always use 1d-input (also known as Maple Input), so that is why.

I tried doing the whole thing with 2d-input and the result was that the input in the tex-file looked like this:

\begin{mapleinput}
\mapleinline{active}{2d}{for i to 10 do f := proc (x) options operator, arrow; x^2 end proc; f(x) end do; 1}{\[\]}
\end{mapleinput}

but nothing of that turned up in the dvi-file, only the 10 results.

@pvrbik I always use 1d-input (also known as Maple Input), so that is why.

I tried doing the whole thing with 2d-input and the result was that the input in the tex-file looked like this:

\begin{mapleinput}
\mapleinline{active}{2d}{for i to 10 do f := proc (x) options operator, arrow; x^2 end proc; f(x) end do; 1}{\[\]}
\end{mapleinput}

but nothing of that turned up in the dvi-file, only the 10 results.

test.pdf

@pvrbik 

No images. See the file test.pdf which I produced from your Maple code. It should be attached.

test.pdf

@pvrbik 

No images. See the file test.pdf which I produced from your Maple code. It should be attached.

@pvrbik Well, I'm using Windows.

My latex is handled by Scientific Workplace. It produced a dvi-file, which I printed to file (postscript).

The postscript file I converted to pdf using gsview/ghostscript.

The result looked nice.

Of course you can export to pdf directly from Maple, but that is not what you want, I guess.

@pvrbik Well, I'm using Windows.

My latex is handled by Scientific Workplace. It produced a dvi-file, which I printed to file (postscript).

The postscript file I converted to pdf using gsview/ghostscript.

The result looked nice.

Of course you can export to pdf directly from Maple, but that is not what you want, I guess.

Same thing happens with plot3d.

Maybe animate is finding a coordinate system in which all frames can be displayed?

It would be quite annoying if the following animation changed the view between frames.

animate(plot,[sin(x),x=-a..a],a=1..10);

which it doesn't.

In range = a..b the length of the real interval [a, b] is b-a. The code could be written from that point of view (not unreasonable).

In your example the matrix has integral values (1,2,3,4), so b-a would result in 3.

First 220 221 222 223 224 225 226 Last Page 222 of 231