Maple 2018 Questions and Posts

These are Posts and Questions associated with the product, Maple 2018

I only just noticed the Start.mw file being always number 1 in my Recent document list.  I don't recall it being there, ever, and I don't think it should.  Why is it there now?  Anyone else have this?

Hi All,

I recently switched from Maple 18 to Maple 2018. I was trying to execute and old worksheet created with Maple 18 in which a DAE have to be solved numerically. In Maple 18 the worksheet works flawlessly whereas Maple 2018 throws 'Error, (in dsolve/numeric/process_input) invalid specification of initial conditions...'

Initial conditions are given in the form {x1(0) = 1, x2(0) = 2, D(x1)(0) = 1, D(x2)(0) = 0 ....} and are the same in both cases ( I merely executed without any modification the same worksheet in the two Maple versions).

I feel I've missed out something in the changelog... any idea on what is happening?

PS. call to dsolve

dsolve(dsys_numeric, numeric, implicit = true, stiff = true, optimize = true, compile = true):
 

 

 

Hi Guys :)

 

I need some Help with solving a nonlinear system. 

I have 3 equations.

These 3 equations have 7 unknown variables in it. But 5 of them are constants which I don't want to solve. I just want to solve three of them.

I tried it with fsolve but I always get the error :

fsolve({eq1, eq3, eq5}, {a, b, c});
%;
Error, (in fsolve) {eq1, eq3, eq5} are in the equation, and are not solved for

 

i tried to define the variables as Parameters but then i get this error: 

Parameters(t1, t2, t3, t4, t5, t6, t7, b1, t, v1, v2, s1, s2, j, a, b, c);

fsolve({eq1, eq3, eq5}, {ca, cb, cc});
%;
Error, (in fsolve) {b1, eq3, eq5, j, t, t1, t2, t3, t4, t5, t6, t7} are in the equation, and are not solved for


Here is the script : Non-Linear_system.mw

 has sb an Idea?

 

result3.mw
 

NULL

with(LinearAlgebra); restart; delta := 0.407e-9; C := 2023.2; L := 5*delta

0.2035e-8

(1)

eq := (1/12)*delta^2*S^4+S^2+omega^2/C^2

0.1380408333e-19*S^4+S^2+0.2442993814e-6*omega^2

(2)

solve(eq, S)

0.7244233290e-6*(-0.6902041665e32+2760816666.*(-0.8430822546e19*omega^2+0.6250000000e45)^(1/2))^(1/2), -0.7244233290e-6*(-0.6902041665e32+2760816666.*(-0.8430822546e19*omega^2+0.6250000000e45)^(1/2))^(1/2), 0.7244233290e-6*(-0.6902041665e32-2760816666.*(-0.8430822546e19*omega^2+0.6250000000e45)^(1/2))^(1/2), -0.7244233290e-6*(-0.6902041665e32-2760816666.*(-0.8430822546e19*omega^2+0.6250000000e45)^(1/2))^(1/2)

(3)

U := _C1*exp(sqrt(-2*C*(3*C-sqrt(-3*delta^2*omega^2+9*C^2)))*x/(C*delta))+_C2*exp(-sqrt(-2*C*(3*C-sqrt(-3*delta^2*omega^2+9*C^2)))*x/(C*delta))+_C3*exp(sqrt(-2*C*(3*C+sqrt(-3*delta^2*omega^2+9*C^2)))*x/(C*delta))+_C4*exp(-sqrt(-2*C*(3*C+sqrt(-3*delta^2*omega^2+9*C^2)))*x/(C*delta))

U2 := diff(U, x)

1214414.026*_C1*(-24560029.44+4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*exp(1214414.026*(-24560029.44+4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*x)-1214414.026*_C2*(-24560029.44+4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*exp(-1214414.026*(-24560029.44+4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*x)+1214414.026*_C3*(-24560029.44-4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*exp(1214414.026*(-24560029.44-4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*x)-1214414.026*_C4*(-24560029.44-4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*exp(-1214414.026*(-24560029.44-4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*x)

(4)

A := simplify(Matrix(4, 4, [[coeff(subs(x = 0, U), _C1), coeff(subs(x = 0, U), _C2), coeff(subs(x = 0, U), _C3), coeff(subs(x = 0, U), _C4)], [coeff(subs(x = L, U), _C1), coeff(subs(x = L, U), _C2), coeff(subs(x = L, U), _C3), coeff(subs(x = L, U), _C4)], [coeff(subs(x = L, U2), _C1), coeff(subs(x = L, U2), _C2), coeff(subs(x = L, U2), _C3), coeff(subs(x = L, U2), _C4)], [coeff(subs(x = 0, U2), _C1), coeff(subs(x = 0, U2), _C2), coeff(subs(x = 0, U2), _C3), coeff(subs(x = 0, U2), _C4)]]))

Matrix(%id = 18446746958277761134)

(5)

solve(Determinant(A) = 0)

Warning,  computation interrupted

 

NULL

NULL

``


 

Download result3.mw
 

NULL

with(LinearAlgebra); restart; delta := 0.407e-9; C := 2023.2; L := 5*delta

0.2035e-8

(1)

eq := (1/12)*delta^2*S^4+S^2+omega^2/C^2

0.1380408333e-19*S^4+S^2+0.2442993814e-6*omega^2

(2)

solve(eq, S)

0.7244233290e-6*(-0.6902041665e32+2760816666.*(-0.8430822546e19*omega^2+0.6250000000e45)^(1/2))^(1/2), -0.7244233290e-6*(-0.6902041665e32+2760816666.*(-0.8430822546e19*omega^2+0.6250000000e45)^(1/2))^(1/2), 0.7244233290e-6*(-0.6902041665e32-2760816666.*(-0.8430822546e19*omega^2+0.6250000000e45)^(1/2))^(1/2), -0.7244233290e-6*(-0.6902041665e32-2760816666.*(-0.8430822546e19*omega^2+0.6250000000e45)^(1/2))^(1/2)

(3)

U := _C1*exp(sqrt(-2*C*(3*C-sqrt(-3*delta^2*omega^2+9*C^2)))*x/(C*delta))+_C2*exp(-sqrt(-2*C*(3*C-sqrt(-3*delta^2*omega^2+9*C^2)))*x/(C*delta))+_C3*exp(sqrt(-2*C*(3*C+sqrt(-3*delta^2*omega^2+9*C^2)))*x/(C*delta))+_C4*exp(-sqrt(-2*C*(3*C+sqrt(-3*delta^2*omega^2+9*C^2)))*x/(C*delta))

U2 := diff(U, x)

1214414.026*_C1*(-24560029.44+4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*exp(1214414.026*(-24560029.44+4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*x)-1214414.026*_C2*(-24560029.44+4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*exp(-1214414.026*(-24560029.44+4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*x)+1214414.026*_C3*(-24560029.44-4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*exp(1214414.026*(-24560029.44-4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*x)-1214414.026*_C4*(-24560029.44-4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*exp(-1214414.026*(-24560029.44-4046.4*(-0.496947e-18*omega^2+36840044.16)^(1/2))^(1/2)*x)

(4)

A := simplify(Matrix(4, 4, [[coeff(subs(x = 0, U), _C1), coeff(subs(x = 0, U), _C2), coeff(subs(x = 0, U), _C3), coeff(subs(x = 0, U), _C4)], [coeff(subs(x = L, U), _C1), coeff(subs(x = L, U), _C2), coeff(subs(x = L, U), _C3), coeff(subs(x = L, U), _C4)], [coeff(subs(x = L, U2), _C1), coeff(subs(x = L, U2), _C2), coeff(subs(x = L, U2), _C3), coeff(subs(x = L, U2), _C4)], [coeff(subs(x = 0, U2), _C1), coeff(subs(x = 0, U2), _C2), coeff(subs(x = 0, U2), _C3), coeff(subs(x = 0, U2), _C4)]]))

Matrix(%id = 18446746958277761134)

(5)

solve(Determinant(A) = 0)

Warning,  computation interrupted

 

NULL

NULL

``


 

Download result3.mw

 

 

I am trying maplemint for first time, but some of the messages it generates do not seem to make sense to me and they all seem to be false alarms.

And not sure how make maplemint generate true warnings to make it easier to filter the real problems from the not real ones. For example, I made some module to try

my_module:=module()

export foo;
local  f,A,n,x;

#private stuff here
f:= x -> x^2:

A := int(f(x)*sin(n*x),x=0..Pi) assuming n::integer;

#public stuff here
foo:= proc()
        A;
end proc;     
    
end module;

maplemint(my_module) generates

Module my_module() 
  These local variables were never used:  x
  These local variables were used but never assigned a value:  n
  These local variables were assigned a value, but otherwise unused:  f

Well, "x" is clearly used. It is the integration variable?  And I can't assign value to "n", it is just a symbol used in the symbolic integration and assumed to be integer.

It also says "f" is not used. But "f" is used in definition of "A" inside the integrand.

So all these messages are not really needed. Is there a way to make maplemint not generate these? I do not see how I could change the code to remove these messages. Is something wrong with my code above?

Code works as expected

my_module:-foo();  gives (-Pi^2*(-1)^n*n^2+2*(-1)^n-2)/n^3

Here is another simpler example of where maplemint messages can't be removed no matter what.

restart;
foo:= proc()
	 local x;
	 plot(sin(x),x=-Pi..Pi);
end proc;     

and maplemint(foo) gives

Procedure foo()
  These local variables were used but never assigned a value:  x

restart;
boo:= proc()	
	 plot(sin(x),x=-Pi..Pi);
end proc;

And now

maplemint(boo);
Procedure boo()
  These names were used as global names but were not declared:  x

Here is another example where maplemint complains about option names for plot3 being undeclared

restart;
foo:= proc()	
    local p,x,y;
    p:=plot3d(sin(x)*cos(y),x=0..Pi,y=0..Pi,
              axes = none, projection=0.9, 
              orientation=[-30,55,0], scaling=unconstrained
              ):
    p:
end proc:

And

maplemint(foo);
Procedure foo()
  These names were used as global names but were not declared:  
     axes, none, orientation, projection, scaling, unconstrained

  These local variables were used but never assigned a value:  
       x, y

If one has to go each time through 100's of messages like these in order to find 1 or 2 real ones which indicate real problems, then using maplemint is not going to an effective way to find problems in code.

Basic question on Maple scoping, having hard time finding it doing search.

I noticed when I do this

get_plot:= proc()     
    plot(sin(x),x=-Pi..Pi);
end proc:

Maple did not complain that `x` inside the proc() was implicitly declared. So this tells me that `x` is set local in scope to the body of the plot() itself and this is done automatically. right?  This is same as in Mathematica actually.

But when I did this

get_plot := proc()  
    local x; 
    x:=10;     
    plot(sin(x),x=-Pi..Pi);
end proc:
get_plot();

I got an error that Error, (in plot) unexpected option: 10 = -Pi .. Pi. So my theory was wrong.

While in Mathematica, one can do the above and it will work

getPlot[]:=Module[{x},
  x=10;
  Plot[Sin[x],{x,0,10}]
];
getPlot[]

It works, becuase the x inside plot have local scope for the Plot command only and it is not the same as the x outside the plot.

But in Maple, it seems once I declared x to be local, then the plot will use that local x. 

So the question is, why did Maple not complain in the first example above that x is implicilty declared as normally happen when one does something like

foo := proc()     
    x:=10;     
end proc:

The 'x' is either local or not. which is it? Why above gives warning but not

foo:= proc() 
  plot(sin(x),x=-Pi..Pi); 
end proc:

Basically, I wanted to know if I should write like this

foo:= proc() 
  local x;
  plot(sin(x),x=-Pi..Pi); 
end proc:

or without the local x if not needed.

Dear Friends, 

I would appreciate your help in resolving some issues. Let me describe my dummy code and the issues I am having. 

I want to know the proper value of two parameters beta and `ΔA` in a tripe integral function  by the NonlinearFit command.The triple integral function is complex.

The code of function is below:

int(tan(beta)^2*exp(-Pi*tan(beta)^2*((x-varepsilon)^2+(0-varsigma)^2)/eta^2)/eta^2, [eta = 22.83-sqrt((5.83+`ΔA`)^2-varepsilon^2) .. 22.83+sqrt((5.83+`ΔA`)^2-varepsilon^2), varepsilon = -5.83-`ΔA` .. 5.83+`ΔA`, varsigma = -1 .. 1])-(int(tan(beta)^2*exp(-Pi*tan(beta)^2*((x-varepsilon)^2+(0-varsigma)^2)/eta^2)/eta^2, [eta = 22.83-sqrt(5.83^2-varepsilon^2) .. 22.83+sqrt(5.83^2-varepsilon^2), varepsilon = -5.83 .. 5.83, varsigma = -1 .. 1])) 

And this is the complete code:

datax := [-8, -4.5, -.5, 4.5, 8, 11.5, 14.5];

datay := [0.287e-2, 0.266e-2, 0.259e-2, 0.199e-2, 0.164e-2, 0.113e-2, 0.78e-3];

f := NonlinearFit(int(tan(beta)^2*exp(-Pi*tan(beta)^2*((x-varepsilon)^2+(0-varsigma)^2)/eta^2)/eta^2, [eta = 22.83-sqrt((5.83+`ΔA`)^2-varepsilon^2) .. 22.83+sqrt((5.83+`ΔA`)^2-varepsilon^2), varepsilon = -5.83-`ΔA` .. 5.83+`ΔA`, varsigma = -1 .. 1])-(int(tan(beta)^2*exp(-Pi*tan(beta)^2*((x-varepsilon)^2+(0-varsigma)^2)/eta^2)/eta^2, [eta = 22.83-sqrt(5.83^2-varepsilon^2) .. 22.83+sqrt(5.83^2-varepsilon^2), varepsilon = -5.83 .. 5.83, varsigma = -1 .. 1])), datax, datay, x)

I try to run it and get the value of parameters beta and `ΔA` ,but I keep getting this error,

Error, (in Statistics:-NonlinearFit) integration range or variable must be specified in the second argument, got HFloat(1.0) = HFloat(16.073603031200726) .. HFloat(29.58639696879927)
Does someone how to deal with this problem?

I would sincerely appreciate any inputs in this regard. 

 

In Mathematica, one can define a function 2 ways. Using delayed evaluation of its RHS (which is same as proc() in Maple) but also as immediate evaulation of its RHS.

In the immediate evaluation, what happens is that the RHS is evaulated first using normal evaluations, then the result of this evaluation becomes the new body of the function.

This can be very useful sometimes. For examle, if the RHS was a complicated integral, which can be evaluated immediatly and gives a result, which still depends on a parameter to fully evaluate, then this method saves having it to evaluate the full integral each time as with the case of delayed evaluation.

I do not know how to emulate immediate evaluation, but using a proc() in Maple. Here is a simple example to explain.

restart;
foo:=proc(n::integer)
     local r;
     r:=int(x*sin(n*x),x=0..Pi);
     r;
end proc;

(ps. I added the extra `r` there just for debuging. They are not needed)

Now when doing foo(3), then the integral will have to be computed each time for each `n`.

But If the integral was evaluated at time of the function definition, it will have the result of -(-1)^n*Pi/n and now when the function is called, then it will be much faster, since in effect the calling the function would be as if one typed

restart;
foo:=proc(n::integer)
     local r;
     r:=-(-1)^n*Pi/n;
     r;
end proc;

In Mathematica, I can do the above by defining a function using `=` instead of the delayed `:=`

foo[n] = Assuming[Element[n, Integers], Integrate[x Sin[n*x], {x, 0, Pi}]]

Now when I do f[3], it will actually use -(-1)^n*Pi/n as the body of the function since the RHS side of the function was evaluated immediatly at time the function was defined. This saves having to do the integral each time.

To make it work like in Maple, the one must make it delayed, like this

foo[n] := Assuming[Element[n, Integers], Integrate[x Sin[n*x], {x, 0, Pi}]]

How can one emulate the immediate evaluation of a proc() in Maple? If not the whole body, but may be a statment? as if one can do

restart; foo:=proc(n::integer) 
      local r; 
      r:=eval_now(int(x*sin(n*x),x=0..Pi)); #result of int is used in definition
      r; 
end proc;

so that the body of the proc will be evaluated as much as possible at time of definition? This can be much more efficient in some cases.

I know ofocurse I could write

foo:=int(x*sin(n*x),x=0..Pi) assuming n::integer;

and then use subs() to evaluate for different `n`. But I wanted to use proc().

 

To make animations, one must generate many plots. The following are two methods I know about. Which would be better? And is there a more efficient way than any of these?

This one pre-allocates an Array of the correct size needed, then fills it in in the loop. But then one has to convert the whole Array back to a list in order to animate it

restart;
nFrames := 10:
frames  := Array([seq(0,i=1..nFrames)]):
w       := 0:
for i from 1 to nFrames do
      frames[i] := plot(sin(w*t),t=-2*Pi..2*Pi);
      w         := w+1;
od:
plots:-display(convert(frames,list),insequence=true);

 

This method does not need to convert an Array to a list. But it does not pre-allocate memory needed before and has to dynamically grow the list each time, which might not be efficient

restart;
nFrames :=10:
frames  := NULL:
w       := 0:
for i from 1 to nFrames do
      frames := frames , plot(sin(w*t),t=-2*Pi..2*Pi);
      w      := w+1;
od:
plots:-display(frames,insequence=true);

For very large number of frames, I am not sure which is better. It is always best to pre-allocate memory to avoid dynamic growing list, which can be costly. But on the other hand, the first method requires converting the whole Array to a list, and I was not sure if that is done in-place or if Maple will have to copy the whole thing again to make a list.

Are there better and more efficient ways to do the above?

I am learning how to do animations in Maple, and I need to export an animation I made to animated gif file.

nTerms := 20:
lam    := evalf([BesselJZeros(0,1..nTerms)]):
c      := seq(1/lam[n]^2*BesselJ(1,lam[n]/2)/BesselJ(1,lam[n])^2,n=1..nTerms):
mySol  := proc(r,t)
   local n;
   4/Pi*sum(c[n]*BesselJ(0,lam[n]*r)*sin(lam[n]*t),n=1..nTerms);
end proc:

maxTime := 5: (*seconds*)
delay   := 0.03:
nFrames := round(maxTime/delay):
frames  := Array([seq(0,i=1..nFrames)]):

frames  := [seq( plot3d([ r, theta, mySol(r,(i*delay)) ],
                   r      = 0..1,
                   theta  = 0..2*Pi,
                   coords = cylindrical,
                   axes   = none,                    
                   title  = sprintf("%s %3.2f %s","time ",(i*delay),"seconds")
                ),
             i=0..nFrames-1)
           ]:
plots:-display(convert(frames,list),insequence=true);

And the above makes

 

I have few questions which I could not find an answer for.

How to save the above sequence of images frames (in the list frames) to an animated gif file programmatically? Currently, I use plots:-display(frames,insequence=true); and then right-click on the screen out, select export->GIF  and this does save the file as animated file.

The problem with the above method, is that I have no control on telling Maple some options. For example, I want to control the amount of delay between each frame when it is played in the web page. I also want to tell Maple for example to play this once in the gif file.

These options are suppored in Mathematica. But I do not see how to do them in Maple. In Mathematica, given a list of frames (generted from a Plot command), which is the variable "frames" in the above Maple code, then one can do this

Export["anim.gif",frames,"DisplayDurations"->Table[.2,{Length@frames}]]

Now when loading anim.gif in a browser, the delay between each frame is 0.2 seconds. The "DisplayDurations" set the delay between each frame when played in the browser  automatically.

One can also add the option

"AnimationRepetitions" -> 1

and this will make the animation play one time in the browser when first loaded. Now Maple generated animation gif file plays continuously which I do not want to, this is even though inside the notebook, Maple says it will play "single" time. But this option does not seem to be exported to the animation gif file

 

 

Is there a way to configure these options? When I right-click, and export the animation to GIF file, I see no export options to change.

I could not use the export("anim.gif",frames)  command in Maple, the generated GIF file is not animated.

thank you

I am looking at the help pages, and I see Maple code using symbols never seen in Maple language before.

I tried to do ?&under to get help on this new Maple language command/symbol, but help does not show it. I read help Neutral Operators but do not understand it.

What does the following mean in plain Maple code?

And what does the following mean using Plain Maple code:

 

Could the above be written without using these `&` things?  I am having hard time understanding what the code is doing because of these. Never used them before.

These are from help on "Definition of a Structured Type in Maple"

I need my results are nice and neat in final presentation so how can I change the way it present matrix in maple, its so messy in hear like picture . It happend resulted in Maple can reduce the same ratio such as As^2+Bs^2=(A+B)s^2, I tried all my best to find way to simply it but its so hard due to my noob in maple. Please help me make it nice and neat in array of matrix [    ]. 

I have the following equation:

eqn := m*`ℓ`^2*(diff(q[1](t), t, t))+k[t]*`ℓ`^2*q[1]+5*k[r]*q[1]-4*k[r]*q[2]+k[r]*q[3]-5*P*`ℓ`*q[1]+2*`ℓ`*P*q[2]+2*`ℓ`*T*q[1]-`ℓ`*T*q[2] = 0;

And I want to execute the following substitutions:

k[r]/(k[t]*`ℓ`^2) = alpha;
P/(k[t]*`ℓ`) = sigma
T/(k[t]*`ℓ`) = theta

For that, I have tried:

expand(eqn/(k[t]*`ℓ`^2));
eqn1:= algsubs({k[r]/(k[t]*`ℓ`^2) = alpha, P/(k[t]*`ℓ`) = sigma, T/(k[t]*`ℓ`) = theta}, %);

And:

eqn1:= algsubs(k[r]/(k[t]*`ℓ`^2) = alpha, %);
eqn2:= algsubs(P/(k[t]*`ℓ`) = sigma, %);
eqn3:= algsubs(T/(k[t]*`ℓ`) = theta, %);

But none of these have worked. Does anyone know how to solve this?

Thanks in advance.

Hi all,

I have an differential equation in terms of the D-operator and am trying to convert it to diff form. Using convert/Diff works fine as long as partially evaluated functions don't appear in the equation. However, I can't figure out how to get the two to cooperate.

For instance, running

D[2](eta)(t,x)+D[2](phi)(t,x,0)+D[2](phi)(t,x,0):
convert(%, Diff);

returns

D[2](eta)(t,x) + Diff(phi(t,x,0),x)

Why is the eta term not converted to diff(eta(t,x),x)?

Thanks a lot!

First 57 58 59 60 61 62 Page 59 of 62