Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

sqrt(4) gives 2 in CAS systems, since the principal root is returned by default. 

Is there an option to have Maple return all roots? Which in this case 2,-2?

I'll explain the context why I need this.

When I solve an ODE, I get a solution that I need to solve for constant of integration C from initial conditions. For an example assume the ODE becomes, after replacing initial condition the following  eq:=4^(1/2) = -2+_C1;

So now when solving for _C1  in maple and then calling simplify, gives one solution which _C1=4 (case root=2) which when replaced back into the general solution gives the particular solution.

But this means the second solution is lost, which is when _C1=0  (case root=-2) which could have been obtained from the non-principal root of 4^(1/2)

eq:=4^(1/2) = -2+_C;


And I would like to get {4,0} instead.

In practice, this becomes important.

Here is an actual ODE, which should have 2 solutions. Mathematica gives both solutions, and Maple gives one solution.  This is due to the above.


In Mathematica


The second solution above came from when constant of integration is zero. The first solution is the one Maple  gave (when expanded).

When I worked the solution by hand, I tracked this to issue with sqrt(4) giving 2 and not +2,-2 when doing solve() to solve for C at the end.

I could ofcourse leave C=sqrt(4)  and not call simplify  on it  and that works.

But I thought to ask here to see if there is some option in Maple, so that when it sees (n)^m to return all m roots when calling solve() and not just the principal one. Even for m=2. 

I looked at root and tried allsolutions=true but they did not help. Looked at solve/details and did not spot something. I tried only few of the options there, as there are so many.

Any suggestions what to try?


I'm searching for the codes in maple to calculate the Lie bracket and adjoint actions on the infinitesimal vectors. 

For eg. if I'm having my vector V3 and V4 as

I am trying to use this command

plot({0, 2*x^2, 2*x^2 - 2*x^3 + 8/3*x^4 - 4*x^5}, x = -10 .. 10, color = ["DarkGreen", "CornflowerBlue", "Burgundy"])

However, only the last function is showing up. 0 and 2x^2 is not showing up. I can't change the axes sizes because then the last function disappears.

I would like to plot results that combine numerical solutions from odes with polynomials (from a collocation procedure). Here is the part of the worksheet:

What is the best way to plot the approximate solutions here? 


Suppose that S={p1, p2, p3, p4},  where

              p1(x)=  71+73x−153x2−259x3−108x4+245x5,

              p2(x)=  37+189x+287x2−167x3+279x4−51x5,

              p3(x)=  -199−200x−62x2+59x3+262x4−70x5,

              p4(x)= 48+295x+18x2+235x3+209x4+279x5,  and

                p(x)= 6143+20711x+8974x2−30368x3+18964x4+17937x5.


To avoid typing errors, you can copy and past the following sequences to your Maple worksheet.




The polynomial p  is a linear combination of S  written in the form


αp1+βp2+γp3+δp4 .


Find a possible set of values for α, β, γ, δ.  Enter the values of α, β, γ, δ  as a sequence in the box below






Suppose that S={u1,u2,u3,u4,u5,u6}⊂ℝ5  where

u1=  < 

u2 = <-65, -11, -47, 18, -15>

u3 = <-240, 90, -265, 495, -175:>

u4= <-53, 70, 84, -80, 61>

u5= <9, 0, 46, -55, -37>

u6 =< 176, -280, -520, 540, -96>

Find a possible set of values for λ1, λ2, λ3, λ4, λ5, λ6, not all zero, such that  


λ1u1+λ2u2+λ3u3+λ4u4+λ5u5+λ6u6=0 .


Enter the values of  λ1, λ2, λ3, λ4, λ5, λ6  as a sequence in the box below


[λ1, λ2, λ3, λ4, λ5, λ6]= 


Hint: There are infinitely many solutions for λ1, λ2, λ3, λ4, λ5, λ6 .   The solution given by Maple will be in terms of parameters. To get one possible set of values, not all zero, choose some nice values for the parameters.



Dear All.

I hope we are all staying safe.

Please I want to solve Sine Gordon Equation using a numerical method I constructed (non-classical), I need to compare the result of the method with the exact solution to generate the errors. However, since the exact solution has two variables, x, and t, I really don't know how to accommodate the two in my coding.

Can someone be of help in this regard?

Thank you and kind regards






How can I use assmptions in partial differential equations?

For example consider the following differential equation

sol:=pdsolve(pde,build) assuming alpha=0

This gives me the same solution if alpha!=0

I also tried this


I again got the same result as if alpha!=0. Except this time there was a tilde on the right side of alpha (to my knowledge that means there are assumptions on alpha)

How do you apply assumptions in PDEs? 



Hi I was wondering if this is allowed and possible, because of the convienience of being able to call it up with the ?[command name] command, it would be an ideal scenario to write extensive notes for procedures and commands I write myself or written by others that are not part of the original maple install, I forget why and how to use alot of the things i write and this would be convienient for me to have quick access to, also to share with others on here or on stack exchange when maple has a stack exchange community.

How find one curve fitting exponential  equation (or any other curve fitting) for the points:

X := [-0.012, -0.010, -0.004, -0.002, -0.001, -0.0001, 0.0001, 0.001, 0.002, 0.004, 0.010, 0.012];
Y := [-0.695, -0.7, -0.74, -0.825, -0.95, -1.0, 1.0, 0.95, 0.825, 0.74, 0.7, 0.695];

I tried, but it wasn't. Look:

X := [-0.012, -0.010, -0.004, -0.002, -0.001, -0.0001, 0.0001, 0.001, 0.002, 0.004, 0.010, 0.012];
Y := [-0.695, -0.7, -0.74, -0.825, -0.95, -1.0, 1.0, 0.95, 0.825, 0.74, 0.7, 0.695];

f := c + exp(-b*x);
                       f := c + exp(-b x)

Statistics*[NonlinearFit](f, X, Y, x);

Statistics [NonlinearFit(c + exp(-b x), [-0.012, -0.010, -0.004,  -0.002, -0.001, -0.0001, 0.0001, 0.001, 0.002, 0.004, 0.010, 

  0.012], [-0.695, -0.7, -0.74, -0.825, -0.95, -1.0, 1.0, 0.95, 0.825, 0.74, 0.7, 0.695], x)]

The Maple not find the curve.

I should get a curve like that (exemple):


I can't understand why select(has,3*C,x) returns 1  and select(has,3+C,x) returns 0

I was expecting to get NULL or {}. But when doing select(has,[3*C],x) and select(has,[3+C],x)  now both return [ ] as expected

Where did 1 and 0 come from in the above examples? I looked at help page, but do not see it.



or the same:



The select function selects the operands of the expression e which satisfy
the Boolean-valued procedure f, and creates a new object of the same type
as e. Those operands for which f does not return true are discarded in the
newly created object.


The above is the same as if one typed




I am trying to learn how do somethings without using pattern matching and it is a struggle so far for me.

For an example, now I want to ask Maple to tell me if C[1] (which is a constant) exist in expression, as long as C[1] does not occur as argument to exp(....)

I'll explain why I want to do this and show small example and show how I ended solving it and ask if there is better way.

Given this expression (this can be result of dsolve for example. Made up here)

I just need to determine if the expression has C[1] anywhere, which is NOT an argument to exp(). In the above example, there is one.

The reason I want to find this, is that this is the constant of integration for first order ODE, and I want to repalce exp(C[1]) by constant C[1], but as long as there is no C[1] allready anywhere in expression on its, otherwise I need to introduce new constant C[2], which I do not want to do (since first order, should have only one constant of integration) and in this case will leave the expression as is and not try to simplify it.

But indets tells one that C[1] is there, not where. This is what I tried

indets(expr, specfunc(exp));

Now I can find if C[1] is argument to exp(....) from the above or not by more processing. (using applyrule or subsindets, etc...)

But first I still need to to determine if there is C[1] that exist anywhere else, as long it is not inside exp(.....).  If I do 

indets(expr, C[1]);

But this does not tell me the information I want. It just says expression has C[1] somewhere.

I looked at evalindets and looked at applyrule and do not see how to use these to do what I want.

Basically I want to tell Maple this

     indets(expr,C[1], conditional( C[1] is not anywhere inside exp(.....) ))

I can solve this using pattern matching. But I fnd Maple pattern matching awkaward to use sometimes and trying to learn how to do things without it.

So this is how I ended solving it. I replace all the C[1] inside exp(....) with ZZZ. Then use indets again to check if C[1] still there or not. This tells me what I want. 

new_expr:=subsindets(expr, specfunc(exp), ()-> ZZZ);
if indets(new_expr, C[1])<>{} then
   print("C[1] exist outside exp()");
   print("C[1] does not exist outside exp()");

"C[1] exist outside exp()"


new_expr:=subsindets(expr, specfunc(exp), ()-> ZZZ);
if indets(new_expr, C[1])<>{} then
   print("C[1] exist outside exp()");
   print("C[1] does not exist outside exp()");

"C[1] does not exist outside exp()"

is there a better way to do this?

Hello again

I need to find the position of the elements of one list in another list.  Here it is a simple example

L1:=[837, 526, 283, 216, 93, 512, 161, 202, 76, 851, 503, 437, 147, 36, 922];
L2:=[526, 283, 202, 437, 922, 865, 879, 804, 473, 325];

the position of the elements in list L1 is [2, 3, 8, 12, 15].   

For huge lists, this solution is not efficient.  Can that be done faster and less memory demanding? (Threads or Grid safe?).

Many thanks.


I am creating a largish package (i.e., for use by others with the “with” command).

Most of the exported procedures have some derivations associated with the code.  This is at least a partial reason for using Maple.  So, I had organized a worksheet so that each exported procedure has its own section that included pre-coding derivations, the procedure, and some post-coding validation of the code (serious testing is done elsewhere).  At the end of the worksheet I had a section that built the module and saved it to the appropriate library.  If I execute the worksheet it runs through everything and builds a new version of the library containing the package.

Getting these exported procedures to bind to a local helper procedure that is shared among several exported procedures was a bit tricky.  The way I ended up doing it is illustrated in the attached worksheet.

From a life cycle perspective is there a better way to think about this?



[Display, FromMathContainer, MakeInert, NoSimpl, Parse, SameStructure, ToMathContainer, ToMathML, Typeset, Value]


DistWorkSheet := proc (A, B) F(A[1]-B[1])+F(A[2]-B[2]) end proc

proc (A, B) F(A[1]-B[1])+F(A[2]-B[2]) end proc



"  export Dist"


"  option package;"


Sqr := proc (A) A*A end proc


Dist := eval(subs(F = eval(Sqr), eval(DistWorkSheet)))

"end module"




proc (A, B) (proc (A) A*A end proc)(A[1]-B[1])+(proc (A) A*A end proc)(A[2]-B[2]) end proc


Test:-Dist([0, 0], [1, 1])






Given some expression, I want to replace each exp(.....) in it with something else.

This is what I currently do. First I find all the exp() terms, then using a loop and use subs  like this


#find all exp terms

Now, lets says I want to replace each with Z

I tried to use but that did not work.

So now I am doing this

for item in s do

is it possible do this without a loop? could not do it using ~

With map, I can do this map(x->subs(x=Z,expr),s) but this does not replace it inside expr where I want. 

Assignment is not allowed inside the above so I can not do  this map(x->expr:=subs(x=Z,expr),s)

And if I do expr:=map(x->subs(x=Z,expr),s)  it does not work either. it gives


How to do the replacement without using a do loop? 



First 7 8 9 10 11 12 13 Last Page 9 of 1698