Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

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? 



I have the following question, plot the graph of mu=5*log_10(D_L/10) where D_L=(c/H_0)*\int_0^z dz'/[A(1+z')^4+B(1+z)^3+C]^{1/2} with resepct to z, where A,B,C are numerical values given beforehand, and c is the speed of light and H_0 is the current Hubble constant.


Can someone please help with this simple plotting assignment.


Thanks, just by experience, can I learnt these syntax languages.


Peace out!


Might anyone be able to tell me what I am doing wrong trying to solve for this ODE?

Thanks so much!

Hi there,

Can someone explain to me why is it happening? If smaller equal than coloured well, if smaller then just the equal line appears. Why?

dm1 := .23; pm12 := .7; dm12 := .23;
inequal(pm1*(dm12+am21)-pm12*(dm1+am21) <= 0, pm1 = 0 .. 1, am21 = 0 .. 1, color = "Nautical 1");


inequal(pm1*(dm12+am21)-pm12*(dm1+am21) < 0, pm1 = 0 .. 1, am21 = 0 .. 1, color = "Nautical 1")

Thank you!

PDEtools[declare](f(x), prime = x);
N := 4;
f(x) :=  sum(p^i*f[i](x), i = 0..N):
HPMEq := (1 - p)*diff(f(x), x $ 3) + p*(diff(f(x), x $ 3) + 1/2*diff(f(x), x, x)*f(x));
for i from 0 to N do
    equ[1][i] := coeff(HPMEq, p, i) = 0;
end do;
cond[1][0] := f[0](0) = 0, D(f[0])(0) = 0, D(f[0])(5) = 1

for j to N do
    cond[1][j] := f[j](0) = 0, D(f[j])(0) = 0, D(f[j])(5) = 0;
end do

for i from 0 to N do
    dsolve({cond[1][i], equ[1][i]}, f[i](x));
    f[i](x) := rhs(%);
end do;
f(x) := evalf(simplify(sum(f[n](x), n = 0 .. N)))

convert(f(x), 'rational')

subs(x = 2.4, diff(f(x), x))

How to sort a matrix based on one particular column in that matrix


Matrix ([[21,30],[8,4]]).  Has to sorted on column one only and output. Matrix ([[8,4],[21,30]]). In this I have given only 2×2  it could be a n×n

Without too much code



Is it  possible to draw an ellipse inscribled in a given triangle and we know its orthoptist circle ? Thank you very much.

## I hope this works. I can't seem to paste my MW file in this window in a readable format.


This is the Maple code


simplify(result,size) ;

Any suggestions?



How to find a rational function with give horizontal asymptotes: y=0.7, y=-0.7 and vertical asymptotes: x=0.001, x=-0.001?


I have a list with a large number of elements and I need to partition it in chunks of a specific size.  Here is my attempt

listpart := proc(cond::list,nchunk::nonnegint:=1000)
if numelems(cond) < nchunk then
end if:
end proc:

It does not run as fast as I thought.  I am not even sure if Threads:-Seq could be used in this case.  Please tell me what I am doing wrong and how I can modify the code to get a faster response.  

Many thanks



5 6 7 8 9 10 11 Last Page 7 of 1695