nm

11353 Reputation

20 Badges

13 years, 11 days

MaplePrimes Activity


These are answers submitted by nm

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. 

I removed bc[4] but the code run withour any error but no solution displayed

It works for me on Maple 2019:


 

restart;

pde := diff(f(x, y), x $ 2) + diff(f(x, y), y $ 2) = 0;
bc[1] := f(x, 0) = exp(-x);
bc[2] := D[1](f)(0, y) = 0;
bc[3] := D[2](f)(x, 1) = 0;
sys := [pde, bc[1], bc[2], bc[3]];
sol := pdsolve(sys, f(x, y))

diff(diff(f(x, y), x), x)+diff(diff(f(x, y), y), y) = 0

f(x, 0) = exp(-x)

(D[1](f))(0, y) = 0

(D[2](f))(x, 1) = 0

[diff(diff(f(x, y), x), x)+diff(diff(f(x, y), y), y) = 0, f(x, 0) = exp(-x), (D[1](f))(0, y) = 0, (D[2](f))(x, 1) = 0]

f(x, y) = Sum(8*sin((1/2)*(1+2*n)*Pi*y)*((n+1/2)*Pi*(2+(1+(n+1/2)*Pi)^2*_C5(n))*exp((1/2)*(1+2*n)*Pi*x)+(n+1/2)*Pi*_C5(n)*(1+(n+1/2)*Pi)*(-1+(n+1/2)*Pi)*exp(-(1/2)*(1+2*n)*Pi*x)+2*exp(-x))/((1+2*n)^3*Pi^3+2*Pi^2*(1+2*n)^2), n = 0 .. infinity)+exp(-x)

 


 

Download foo.mw

One way could be

A:=Matrix([[0,1,0,1],[-1,3,0,0],[0,0,1,0]]);
ArrayNumElems(A,'NonZero')

5

in Maple index starts from 1 not zero. Try

 

f := proc (x, w)
     local k;   
     sum(w[k]*x^k, k = 1 .. nops(w))
end proc;

f(2, [a, b, c]);

No error now

But should not the call be f(x, [a, b, c]) ? I do not know what you are passing 2 there.

 

restart;

#note: no error checking is done. This assumes solution 
#exist and point are not colinear.

get_circle_equation:=proc(pt1,pt2,pt3,x,y)
 local q,p,r,res,eq,sol;
 res:=map(pt->(pt[1]-q)^2+(pt[2]-p)^2=r^2,[pt1,pt2,pt3]);
 sol:=solve(res,[q,p,r]);
 assign(sol);
 return (x-q)^2+(y-p)^2=r^2;
end proc:

pt1:=[1,2];pt2:=[-3,0];pt3:=[5,-4];
cir:=get_circle_equation(pt1,pt2,pt3,x,y);
plots:-implicitplot(cir,x=-10..19,y=-10..10)

 

I normally use unapply for these things as follows

aux := rsolve({y(0) = y0, y(n) = 4*y(n-1)*(1-y(n-1))}, y(n));
solucao := unapply(aux,n,y0);
solucao(3,1/2);

 

 

I can't reproduce this on 2018.2.1 on windows

restart;
with(LinearAlgebra):
switch:=proc(v::Vector)
 local w;
 w:=v;
 w:=[-1,-2,-3];
 w
end proc:
v1:=Vector([1,2,3]):
v2:=switch(v1);
v1;

 

v1 remain unchanged.

But it cause the problem if one changes one element at time, instead of complete assignment, as in:

restart;
with(LinearAlgebra):
switch:=proc(v::Vector)
 local w;
 w:=v;
 w[1]:=-1;
 w
end proc:
v1:=Vector([1,2,3]):
v2:=switch(v1);
v1;

 

Mathematica does not have this confusing behaviour. 

switch[v_] := Module[{w = v},
   w = {-1, -2, -3};
   w
   ];
v1 = {1, 2, 3};
v2 = switch[v1]

v1 remains the same here (like Maple). And

switch[v_] := Module[{w = v},
   w[[1]] = -1;
   w
   ];
v1 = {1, 2, 3};
v2 = switch[v1]

Here also v1 remains unchanged, as expected.  This is the behavior one would expect.  Notice that Mathematica does not have Vector or Matrix special structures, as every is list of lists. Maple behaves the same if ones uses list instead of Vector as well.

Maple seems to always convert sqrt(2)*exp(I*Pi/4)  to 1+I.

 

sqrt(2)*exp(I*Pi/4);

           sqrt(2)*((1/2)*sqrt(2)+I*sqrt(2)*(1/2))

simplify(%);

           1+I

If you want just to print it. you can do

p:=convert(z,polar);
sprintf("%s%a%s%a%s","the number is ", op(1,p), " exp(",(I*op(2,p)), ")");

                           the number is 2^(1/2) exp(1/4*I*Pi)

This is one of those things where CAS does automatic simplification.

Somethink like Matlab pause statment

 

try Threads:-Sleep(n); which maps to Matlab pause(n)

see https://www.maplesoft.com/support/help/maple/view.aspx?path=Threads%2fSleep

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