nm

3161 Reputation

17 Badges

7 years, 320 days

MaplePrimes Activity


These are answers submitted by nm

 

In Section 14.5 - External Calling ..., page 489

 

I do not use Maple on Linux. But you have one ". You need two of these, one of each side. 

Here is the example from book. Try and see if this fixes it.

 

 

 

The first I do myself is usethe option numeric=true as in

          int(sin(x),x=0..Pi,numeric=true)  

Another is evalf(Int(....))

For 99.99% of time this is all what you need to do.  Only in the rare cases where it fail, or you think the result is not right, then you then try to change the method, tune some options and so on.  such as  

method = <name>  or  <name>
digits = <posint>  or  <posint>
epsilon = <numeric>
methodoptions = <list>
maxintervals = <posint>

 

These are all described in evalf(Int(....) web page  

Each case is different. So start with the generic call for numerical integration and worry about what will you do when you get an error or problem. There is no one answer that fits all cases.


expr:=latex('int(1/(x^2+2),x=2..3)')
\int_{2}^{3}\! \left( {x}^{2}+2 \right) ^{-1}\,{\rm d}x

compiles to

 

And you can do things like this


expr:="int(1/(x^2+2),x=2..3)";
result:=cat(latex(parse(expr),output=string)," = ",latex(eval(parse(expr)),output=string));

Which gives latex which compiles to

 

Maple is case sensetive. so P(t) and p(t) are not the same.    Also no need to give range for dependent variable. Also you need to use DEtools.

restart;
ode3 := diff(P(t), t) = 0.2*P(t) - 300;
ICs := [[0, 1300], [0, 1800]];
DEtools:-DEplot(ode3, P(t), t = 0 .. 40, ICs, 
        arrows = LINE, color = RED, linecolor = BLUE,
        title = "Solution Curves ode3");

 

But to use range for dependent variable, from help it says it comes after ICS, like this

 

restart;
ode3 := diff(P(t), t) = 0.2*P(t) - 300;
ICs := [[0, 1300], [0, 1800]];
DEtools:-DEplot(ode3, P(t), t = 0 .. 40, ICs, P = -50 .. 2000,
      arrows = LINE, color = RED, linecolor = BLUE, title = "Solution Curves ode3");

It is not a bug, Isn't this known and due to when evalation and binding names to value happen? When you type f:=(x,y)->eq2 notice that Maple did not replace eq2 with its value y = 10 - 5*x at the time the function is defined.

When you called the function next, maple did not replace the x,y since eq2 was still name. Next, it evaluates eq2 and returns it value which is y = 10 - 5*x but by then it is too late. 

I think this is why unapply was invented.

but to do what you want, you could always write

          f:=(x0,y0)->eval(eq2,[x=x0,y=y0])

And now f(3,1) returns 1 = -5

 

ofcourse Maple can open a CDF file. Any software can open a CDF file, after all, it is just plain text file and not a binary file. Same for Mathematica notebooks. They are all plain text files.

Here is start of one such CDF file

 

(* Content-type: application/vnd.wolfram.cdf.text *)

(*** Wolfram CDF File ***)
(* http://www.wolfram.com/cdf *)

(* CreatedBy='Mathematica 12.1' *)

Now, the question is what you meant to ask is, can Maple run a CDF?  The answer is No. Only WRI software can run CDF files. You need either Mathematica itself or the Wolfram player installed to run a CDF file.

This is becuase it needs the Wolfram kernel software to run it. Just like one needs Maple kernel to Maple worksheet. No difference.

 

I agree with you. It is a problem somwhere. Maple should clearly be able to do this PDE as Maple is very good in solving PDE's.

Here is a work around meanwhile

restart;
bc_new := D[1](u)(0,t)=0, u(1,t)=0;
ic := u(x,0) = f(x); #cos(Pi/2*x);
pde := diff(u(x,t),t) = diff(u(x,t),x$2);
sol:=pdsolve({pde,bc_new,ic},u(x,t));
value(subs(f(x)=cos(Pi/2*x),rhs(sol)))

Gives

 

 

Maple 2020. Physics version  642 

plots[animate]( plot, [exp(-Pi^2*t/4)*cos(Pi*x/2), x=0..1], t=0..1.2,frames=100 );

 

one way

lst := Vector():
n   := 1;
for i from 11 to 20 do 
    lst(n) := i^2;
    print(lst[n]);

    n := n+1;    
od:

 

Another

f:=proc(i) print(i^2); i^2; end proc;
lst:=[seq(f(i),i=11..22)]

Another, if you do not want to print

lst:=[seq(i^2,i=11..22)]

I am sure one can come up with many more ways to do this.

 

You can start by adding Geogebra to your PATH in windows (I assume you know how to do this).

Also, try the following 

restart;
res:=ssystem("where ping"):
res[2]

This on my PC returns  "C:Windows\System32\PING.EXE"

 

If res[1] returns 1, it means it failed. If res[1] is zero, it means it worked. So you can add a check in that in your program also.

The command where should be on windows 10 (I use windows 10).  This command returns the full path of the program. If it does not, it means it could not find it. That is why I suggested adding it to your PATH in case it failed. 

"By default, WHERE searches the current directory and the paths specified in the PATH environment variable."

You can test the where command from DOS first. One you get the above, then you can now do the next command to launch it.

 

 

 

I am going to assume you meant fixed length string and u(0,t)=0=u(0,1) is a typo and you meant  u(0,t)=0=u(1,t)

restart;
pde := diff(u(x,t),t$2)=c^2*diff(u(x,t),x$2);
bc  := u(0,t)=0,u(L,t)=0;
ic  := u(x,0)=f(x),D[2](u)(x,0)=g(x);
sol:=pdsolve([pde, ic, bc],u(x,t)) assuming L>0;

To do animation, we need to put specific values. For example

L:=1;
c:=2;
g:=0;
f:=(8*x*(L-x)^2)/L^3;
pde := diff(u(x,t),t$2)=c^2*diff(u(x,t),x$2);
bc  := u(0,t)=0,u(L,t)=0;
ic  := u(x,0)=f,D[2](u)(x,0)=g;
sol:=pdsolve([pde, ic, bc],u(x,t));
sol:=subs(infinity=15,sol); #should be good enough

 

Another example

 

restart;
c:=2;
pde := diff(u(x,t),t$2)=c^2*diff(u(x,t),x$2);
bc  := u(-Pi,t)=0,u(Pi,t)=0;
ic  := u(x,0)=0,D[2](u)(x,0)=sin(x)^2;
sol:=pdsolve([pde, ic, bc],u(x,t));
sol:=subs(infinity=20,sol);

If you search the internet, there are hundreds of such examples out there. 

 

restart;
pde  := diff(u(x,t),t$2)= diff(u(x,t),x$2);
f    := x->piecewise(-1/2<x and x<1/2,5*cos(Pi*x),true,0);
ic   := u(x,0)=x, D[2](u)(x,0)=f(x);
sol  := pdsolve([pde,ic],u(x,t));
plots:-animate(plot, [rhs(sol),x=-6..6],t=0..10);

 

update

Thanks to the hint by Carl below, I can now save animation to gif file. Made a new one by making small change to the initial conditions given above just to make the wave motion a little bit more interesting looking. I am surprised how fast Maple saved the animation gif file to disk. This is good.

restart;
pde :=  diff(u(x,t),t$2)= diff(u(x,t),x$2);
f   :=  x->piecewise(-1/2<x and x<1/2,10*cos(Pi*x),true,0);
ic  :=  u(x,0)=f(x), D[2](u)(x,0)=0;
sol := pdsolve([pde,ic],u(x,t));

plots:-animate(plot, [rhs(sol),x=-10..10],t=0..10,frames=100);

restart;
PDE := diff(u(x, t), t) - VectorCalculus:-Laplacian(u(x, t), [x]) - u(x, t) + x - 2*sin(2*x)*cos(x) = 0;
IBC := D[1](u)(Pi/2, t) = 1, u(0, t) = 0, u(x, 0) = x;
pdsolve(eval(PDE), {IBC}, type = numeric);

 

Works OK on Maple 2020. 

 

Or you can try analytical solution

restart;
PDE := diff(u(x, t), t) - VectorCalculus:-Laplacian(u(x, t), [x]) - u(x, t) + x - 2*sin(2*x)*cos(x) = 0;
IBC := D[1](u)(Pi/2, t) = 1, u(0, t) = 0, u(x, 0) = x;
pdsolve([PDE,IBC]);

 

Both work. No error. Attached worksheet.


 

 

restart;
PDE := diff(u(x, t), t) - VectorCalculus:-Laplacian(u(x, t), [x]) - u(x, t) + x - 2*sin(2*x)*cos(x) = 0;
IBC := D[1](u)(Pi/2, t) = 1, u(0, t) = 0, u(x, 0) = x;
pdsolve([PDE,IBC]);

diff(u(x, t), t)-(diff(diff(u(x, t), x), x))-u(x, t)+x-2*sin(2*x)*cos(x) = 0

(D[1](u))((1/2)*Pi, t) = 1, u(0, t) = 0, u(x, 0) = x

u(x, t) = (1/8)*(-exp(-8*t)+1)*sin(3*x)+sin(x)*t+x

restart;
PDE := diff(u(x, t), t) - VectorCalculus:-Laplacian(u(x, t), [x]) - u(x, t) + x - 2*sin(2*x)*cos(x) = 0;
IBC := D[1](u)(Pi/2, t) = 1, u(0, t) = 0, u(x, 0) = x;
sol:=pdsolve(eval(PDE), {IBC}, type = numeric);

diff(u(x, t), t)-(diff(diff(u(x, t), x), x))-u(x, t)+x-2*sin(2*x)*cos(x) = 0

(D[1](u))((1/2)*Pi, t) = 1, u(0, t) = 0, u(x, 0) = x

_m3030174367552

sol:-plot(t=0,numpoints=50)

sol:-plot3d(t=0..1,x=0..5)

 


 

Download maple_sheet.mw

Removed as not needed.

L1:=[1,2,5,6,9];
andmap( x->x>0, L1 );

         true

L2:=[0,-2,5,6,9]:
andmap( x->x>0, L2 );

       false

You can't really expect to translate such code to Maple. Using MmaTranslator or any other tool.

MmaTranslator is meant to translate mathematics from Mathematica syntax to Maple syntax. It also  supports few core Mathematica commands such as Table, If, Do, etc...

So only common mathematical functions and basic constructs that have Maple equivalent can be translated. 

But Manipulate can't be translated to Maple. What do expect Maple to translate Manipulate to?  

Let try it. Here is a full Manipulate program

with(MmaTranslator)
FromMma(`Manipulate[Plot[Sin[c x],{x,-1,1}], {{c,1,"c"},0,2,.1}]`)

Maple returns

Manipulate(plot(sin(c*x), x = -1 .. 1), [[c, 1, "c"], 0, 2, 0.1])

Good luck running the above in Maple.

There are thousands of Mathematica commands that can't be expected to be translated. For example

FromMma(`Graphics3D[Sphere[{0, 0, 0}]]`)

Will just give

Graphics3D(Sphere([0, 0, 0]))

You can't run the above in Maple.

You could translated a Table command for example

FromMma(`Table[i,{10}]`)

Which gives

[seq(i, i = 1 .. 10)]

To translate all of Mathematica commands and functions to Maple means that Maple will have to reimplement all of Mathematica functions inside it (those that have no direct corresponding in Maple ). May be this will take 20 millions or so lines of code to do. Which is not realistic.

 

 

1 2 3 4 5 6 7 Page 1 of 8