nm

11558 Reputation

20 Badges

13 years, 135 days

MaplePrimes Activity


These are answers submitted by nm


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

 

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 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.

 

 

I am sure these functions are important for your work.

But I think given the small resources Maplesoft seem to have, I would prefer Maplesoft put its important resources on things that can impact many more users. Here is a partial list of mine in order or priority (I can add more, but will keep it short)

  1. Fix Latex. myself, will use Maple much more if it has good latex output. This is critical. Most science and math publications use Latex. Maplesoft seems to think Latex is not important for some reason.
  2. Improve the debugger. This is very important and will help so many people to better debug the code. Using the debugger now is a pain compared to other systems.
  3. Improve the help system. On the web, Maple help is terrible (sorry, but true, most of the web pages are not readable). Inside Maple, the help is better, but it is still hard to easily find options and what one wants. Have to read long pages to be able to spot what one wants. Maple help pages need to be much more organized. Also need many more examples.
  4. Improve the user interface. Maple user interface is still not as polished or user friendly as some of the competitors. 

After doing all of the above, then Maplesoft could add these special functions you want :)

Maple 2019.1

Your input is not right. I do not understand what concatentation operator || is doing in the above actually. (did not know one can use || inside matrix)

May be, in simple terms, you can show what is your A,B,C,D matrices are?

This is how I do these things:

restart:
a   := Matrix([[0,1,0,0],[0,0,1,0],[0,0,0,1],[-100,-90,-32,-8]]):
b   := Matrix([[0],[0],[5],[6]]):
c   := Matrix([[1,0,0,0]]):
d   := Matrix([[1]]):
sys := DynamicSystems:-StateSpace(a,b,c,d);

DynamicSystems:-ResponsePlot(sys, 
       DynamicSystems:-Step(),duration=10,color=red,legend="step");

Default digits is 10. Solve gives exact solution. When converted to numerical using only 10 digits you get the difference shown

if you increase the Digits to say 16, now both give the same answer.

restart;

sol:=solve(cos(2*arccos(x)));
evalf(sol);
Digits:=16:
evalf(sol);

(1/2)*2^(1/2)

.7071067810

.7071067811865475

restart;

fsolve(cos(2*arccos(x)));
Digits:=16:
fsolve(cos(2*arccos(x)));
 

.7071067812

.7071067811865475

 

 

Download 072919.mw

"with solutions k*Pi and -Pi/48 + K*Pi/8"

What is K above? Is this supposed to be an integer? If so, the above misses many solutions:

restart;
eq   := sin(9*x-(1/3)*Pi) - sin(7*x-(1/3)*Pi);
pt1  := [seq( [k*Pi,0] ,k=-2..2)];
pt2  := [seq( [-Pi/48+k*Pi/8,0],k=-2..2)];
pt   := [op(pt1),op(pt2)];

plots:-display([
        plot(eq,x=-2*Pi..2*Pi,color=blue),
        plots:-pointplot(pt,color=red,symbol=circle,symbolsize=20)]
       );

 

You can see there are many zeros your solution missed.

There might be a build in function in Maple to do this. But you could always do

N:=10: #must be even integer
lst:=[seq([i,N-i],i=1..N/2)]

corrected to use evalhf instead of evalf (I am not able to delete this for some reason).

It is always best to provide an example when asking such questions to eliminate any misunderstanding.

You could try

r:=evalf(Pi); 
parse(sprintf("%.10f",r)); #truncate to whatever number of decimals

if this is not what you meant, someone please feel free to delete my answer. I am not able to delete it. 

First 13 14 15 16 17 18 19 Page 15 of 19