Maple 2021 Questions and Posts

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

I need to calculate dozens of piecewise-defined  (but elementary) definite integrals of the following kind. Maple returns them unevaluated. Is there a trick to force evaluation? 

restart;
u := piecewise(0 <= x and 0 <= y and y <= x, x-1, 0 <= x and 0 <= y and x <= y, x, 0);
v := piecewise(0 <= x and 0 <= y and y <= x, x-1, y <= 0 and 0 <= x and -x <= y, x-1, 0);
plot3d(u*v, x=-1..1, y=-1..1);
# integrating over (0,1)x(0,1) works
int(u*v, x=0..1, y=0..1);
# but integrating over (-1,1)x(-1,1) returns unevaluated.
# How to force evaluation on (-1,1)x(-1,1)?
int(u*v, x=-1..1, y=-1..1);

integration-problem.mw

 

given one equation where both sides are polynomials in one variable x, like this

eq:=c1*(x^2+x)+c2*(2+2*x)+c3=-4*x^2+2*x+6;

And we want to solve for the coefficients on the LHS, which are c1,c2,c3.  By hand, this is solved by expanding both sides, and then comparing the coefficient of each power of x. This generates 3 equations (in this example) and then these are solved for c1,c2,c3.

Is there a way to automatically do this in Maple without the user having to do the first manual step of generating the equations needed to solve for c1,c2,c3?

eq1:=c1=-4;eq2:=c1+2*c2=2;eq3:=2*c2+c3=6;
PDEtools:-Solve([eq1,eq2,eq3],[c1,c2,c3])

gives

              {c1 = -4, c2 = 3, c3 = 0}

But It will be nice if there is a command in Maple which will do it starting from the first equation. Ofcourse one has to tell Maple what to solve for. PDEtools:-Solve(eq,[c1,c2,c3]); or solve(eq,[c1,c2,c3]) does not work, because Maple does not know it needs to expand and compare coefficients as we do by hand.

It is not hard to write code to generate these equations, but I am asking if there is already a command in Maple which somehow does it automatically. I looked at SolveTools, but did not spot something yet there.

edit

Ok, I think this is easy to do. I found a command

eq:=c1*(x^2+x)+c2*(2+2*x)+c3=-4*x^2+2*x+6;
eqs:=PolynomialTools:-CoefficientList((lhs-rhs)(eq),x);
PDEtools:-Solve(eqs,[c1,c2,c3])

{c1 = -4, c2 = 3, c3 = 0}

 

 

There is code at Maple app center  here  called "A Simple Expression Parser" which generates the actual tree structure of an expression. I tested it a little and it seems to work correctly on what I tried so far.

My question if some Graph expert could take the output of the above and generate an actual tree graph from it, to make it easier to see, similar to Mathematica TreeForm command which would make it much more useful.

I will show 2 examples, and the code from the above application and what the final graph should look like,. The code is (formatted a little to make it easier to read)

#code from https://www.maplesoft.com/applications/view.aspx?SID=4808
Op := proc(x) 
    if 1 < nops(x) and not type(x, function) then 
       [whattype(x), op(x)]; 
    elif type(x, function) then 
       [op(0, x), op(x)]; 
    else 
        x; 
    fi; 
end proc;

Parse := proc(expr) 
   local tmp, i; 
   tmp := Op(expr); 
   for i from 2 to nops(tmp) do 
       if 1 < nops(tmp[i]) or type(tmp[i], function) then 
          tmp := subsop(i = Parse(tmp[i]), tmp); 
       end if; 
   od; 
   RETURN(tmp); 
end proc;

ps. I do not think using name Parse above is good idea, since I see it is an inert form of Maple build in command.

Now, lets look at this

first example 

expr:=sin(x)+x*y + 1/x;
Parse(expr)

The above says the tree is rooted at `+` with three branches. The first is sin(x), the second is a tree rooted at `*` with two leafs x,y, and the third branch is roots at `^` with two leafs x,-1. Physically it looks like this

Second example

expr := sin(x)*(x + y) + 1/x;
Parse(expr)

Which physically will look like

So it is possible in theory to make a TreeForm command in Maple, using this Parse() command. May be using Graph package in Maple? by reading the output from the Parse() command, and generating nodes and arcs along the way.

How hard will such a task be? I never used the Maple 's Graph package.  

Could may be  someone may be give this an attempt? I never understood why Maple do not have a build in similar command to TreeForm. It is very useful to understanding expressions.

 

I have

f:=a^6*o + a^5*i + a^4*u + a^3*q + a^2*t + a

and

f1:=7*a^6*p + 6*a^5*o + 5*a^4*i + 4*a^3*u + 3*a^2*q + 2*a*t + 1

I want to divide two functions f/f1 to produce a result.

a^2*t+ a^3*(-2*t^2 + 2*q)+ a^4*(4*t^3 - 7*t*q + 3*u)(-8*t^4 + 20*t^2*q - 6*q^3 - 10*t*u + 4*i)*a^5+a^6*(16*t^5 - 52*t^3*q + 33*t*q^3 + 28*t^2*u - 13*i*t - 17*u*q + 5*o)+O(a^7)

 

I have tried collect and asympt, the result is not satisfactory.

 

Hi guys ,

 

I have the equation dt=(L/r)*(1 - a^3/r^3)^(-1/2) dr which want to integrate on both side and then solve in terms of r.(L and a are constants). I know the answer (r=a (cosh(3t/2*L)^2/3),but it seems maple can not produce it!

 

Mathematical almost compute it corectly! altough i think  tanh-1, should be cosh^-1(x/a)^3/2

 

I would appreciate if someone can help me

 

 

 

Thanks so muchproblem.mw

Why does Maple write

restart;
eq:=x-infinity=0;

as 

Update 3 years later

FYI, The above bug is still present in Maple 2024

24688

interface(version);

`Standard Worksheet Interface, Maple 2024.0, Windows 10, March 01 2024 Build ID 1794891`

interface(typesetting=extended):

eq:=x-infinity=0;

x-infinity = 0

 

 

Download wrong_display_of_math_maple_2024_june_28_2024.mw

I've send a bug report to Maplesoft also.

Any one has smart way to help verify this Maple solution to this ODE? I can't figure it out

restart;
ode:=diff(y(x),x)-y(x) = x*y(x)^(1/2):
ic:= y(0)=4:
maple_sol:=dsolve([ode,ic],'implicit'):
the_diff_1:=odetest( (lhs-rhs)(maple_sol)=0,[ode,ic]);


maple_sol:=dsolve([ode,ic],'explicit'):
the_diff_2:=odetest( (lhs-rhs)(maple_sol)=0,[ode,ic]);

Tried few simplifications but not everything. I am assuming Maple solution is correct.

Maple 2021.1

Background

This 'quirk' of Maple behaviour cropped up when I was considering solutions for the question posted here

https://www.mapleprimes.com/questions/232433-Extract-From-Record

where the OP had "poorly structured" data which meant it was a bit "awkward" to access required fields. A number of more-or-less satisfactory solution were proposed, and the OP seems happy

 

The Issue

One possible way to solve the original problem would be to restructure the data as a DataFrame. The "natural" way to do this would be to use numeric row indexes.. Note that these row indexes are not contiguous, and are in no particular order. However using this approach means that accessing fields from the dataframe is not consistent.

Sometimes the supplied row label is interpreted as a 'label', sometimes it is interpreted as the "row number". It appears that the latter interpretation is preferentially used

I can't make up my mind whether to call this a "bug" or not, but I can see the inconsistent interpretation resulting in chaos.

Before submitting an SCR I'd like to know if anyone else sees this as a bug

Consider the code

  restart;
  prettyprint=1:
#
# data
#
  S := [`206` = Record(mu = 508.001018040,  sigma = 125.002863204708),
          `4` = Record(mu = 1008.001018040, sigma = 167.707232430134),
          `2` = Record(mu = 1208.001018040, sigma = 141.512246146314),
          `5` = Record(mu = 808.001018040,  sigma = 117.156800098735)
       ]:
#
# Construct the above as a dataframe - note row labels are numbers!
#
  DF:= DataFrame( Matrix([seq( [rhs(j):-mu, rhs(j):-sigma], j in S)]),
                  rows= [seq( parse( lhs(j) ), j in S)],
                  columns=[mu, sigma]
              );
  DF[206, mu];
  DF[2, mu];  ## Errr No!
  DF[5, sigma];
               [           mu             sigma      ]
               [                                     ]
               [206  508.001018040   125.002863204708]
               [                                     ]
         DF := [ 4   1008.001018040  167.707232430134]
               [                                     ]
               [ 2   1208.001018040  141.512246146314]
               [                                     ]
               [ 5   808.001018040   117.156800098735]

                         508.001018040

                         1008.001018040

                        117.156800098735

Note that DF[2, mu] outputs the entry from the second row - not the one from the row labelled with the number 2

I imagina a similar issue would occur with numeric column indexes, although I haven't tried this
     

 

 

restart:
with(plots):
kernelopts(version);
 

How do I setup solve to find only the real and imaginary part of Zeta to be both positive and the real part of Zeta to be the smallest positive value? For example: real part = 1.348412872 and imaginary part = 0.04230725448.

Acceleration ratio (db) and phase (deg). Convert ratio to linear and phase to radian. 
dat := <14.52407334|-162.1310124>:
A := 10^(dat[1]/20.):
phi := dat[2]*Pi/180.:
R:= 0.3036:
Characteristic equation Eqn 5
f := (Zeta,A,phi) -> cos(Zeta) - R * Zeta * sin(Zeta) - exp(-phi * I)/A:

soln := [solve(f(Zeta,A,phi), Zeta)]:
 

Tests.mw

Textbook gives this nice short implicit solution for this ode

As

But Maple does not give an implicit solution

restart;
ode:=diff(y(x),x) = 2*(2*y(x)-x)/(x+y(x));
ic:=y(0)=2;
sol:=dsolve([ode,ic],'implicit')

Removing implicit gives very complicated solution as it tries to solve for y(x).

book_sol:=(x-y(x))^2-1/2*(y(x)-2*x)^3=0;
odetest(book_sol,[ode,ic])

Any suggestion or a trick or a different approach to make Maple generate the same solution given in the textbook?

ps. manually, it is possible to obtain the same solution as book as follows

restart;
ode:=diff(y(x),x) = 2*(2*y(x)-x)/(x+y(x));
ic:=y(0)=2;
sol:=dsolve(ode,'implicit');
sol:=simplify(exp(lhs(sol))=exp(rhs(sol)));
the_constant:=solve(sol,_C1);
the_constant:=eval(the_constant,[y(x)=2,x=0]);
sol:=eval(sol,_C1=the_constant);
odetest((lhs-rhs)(sol)=0,[ode,ic])

 

edit june 14,2021

I found a direct way to get an implicit solution which is close enough to book solution. It is by using Lie symmetry method

restart;
ode:=diff(y(x),x) = 2*(2*y(x)-x)/(x+y(x));
ic:=y(0)=2;
sol:=dsolve([ode,ic], y(x),'implicit','Lie');

Another variant which gives book solution but requires one extra step

restart;
ode:=diff(y(x),x) = 2*(2*y(x)-x)/(x+y(x));
ic:=y(0)=2;
sol:=dsolve([ode,ic], y(x),'implicit','Lie',way=all,fat);
simplify(exp( (lhs-rhs)(sol)))=1

ps. corrected above now, thanks to comment below by Carl.

Maple 2021.1

 

 

 

In worksheet mode, when typing only the first 3 letters of the command piecewise, the command completion popup shows and I can hit TAB to have it automatically complete which is nice since I always makes typos tying this command

  >pie

When when I wanted to get help on the same command, I have to type 5 letters now before the popup shows to help me complete the command

 >?piece

Why is that? I would have expected the same 3 letters to be enough, as I assume Maple is smart enough to notice this.

Here is a movie to illustrate. This is Maple 2021.1 on windows 10

   

I have a list of objects. Each object contains many fields, one of these fields happened to be a solution to an ode.

At the end of solving the ODE, I'd like to remove all objects which contain the same solution. 

I can not do the normal trick in Maple to remove duplicates from a list, which is to convert the list to a set and let Maple automatically remove duplicates because in this case each entry in the list is an object of many fields and hence each object is always different. 

I only want to remove the objects from the list which has the same specific field.

Currently what I do is the following:   Do a first scan, and loop over all entries in the list to find the duplicates. Each time I find a duplicate solution, mark a field in the object as it is being duplicate.

Then do another scan at the end, to build a new list, which only adds those objects not marked as duplicates.

It works, but was wondering if Maple or someone might have better suggestion or more elegent way to do this.

In this MWE I am using a list and adding objects to it making it grow dynamically. I know it would be better to use Array, but for now I'd like to stick to a list, since the number of solutions is normally small. May be in the future I will change the list to Array to avoid building a list dynamically.

This example code builds a list of 5 objects

restart;
ode_solution_type:=module()
    option object;
    export sol:=NULL; #only ONE solution here.  
    export stuff;
    export mark_to_delete:=false;
end module:

SOL::list:=[]:  #where to keep the objects

for n from 1 to 5 do
    tmp:=Object(ode_solution_type);
    
    if n=3 then
        tmp:-sol:=y(x)=1;
    else
       tmp:-sol:=y(x)=0;
    fi;
    tmp:-stuff:=rand();
    SOL:=[op(SOL),tmp];
od:

In the above, I made 4 objects to have same solution which is y(x)=0 and one different. The goal is to remove all objects from the list which has duplicate solutions and keep only one copy.

for n from 1 to numelems(SOL) do
    print("sol ", n , "  is ", SOL[n]:-sol);  
od:

And this is how currently I remove the duplicates

for n from 1 to numelems(SOL) do
    for m from n+1 to numelems(SOL) do
        if is(SOL[n]:-sol=SOL[m]:-sol) and not SOL[m]:-mark_to_delete then
           print("found duplicate at ",m);
           SOL[m]:-mark_to_delete:=true;
        fi;
    od;    
od:

#now make new pass to keep the non- duplicates
new_SOL::list:=[]:
for n from 1 to numelems(SOL) do
    if not SOL[n]:-mark_to_delete then
       new_SOL:=[op(new_SOL),SOL[n]];
    fi;    
od:

checking:

for n from 1 to numelems(new_SOL) do
    print("sol ", n , "  is ", new_SOL[n]:-sol);  
od:

Does there exist a better option in Maple (while still using a list?) to remove objects in list which have the same specific field?

Could you suggest a better method?

sometimes I get a solution to an ODE, where when I plugin the initial conditions to solve for the constant of integration, the solution by inspection can be seen to be infinity.

The constant of integration is allowed to be infinity.

But now I get no solution from solve and so my program rejects this solution and says the ode can't be solved because it can't find value for the constant of integration using this initial conditions.

I am not sure how to handle this, since Maple solve will not return an infinity as possible solution for the constant of integration. I tried different assumptions.  

This has to work for general, and not for this specific example I will show now.

Here is an ODE with IC

ode:=diff(y(x),x)=y(x)^3*sin(x);
ic:=y(0)=0;
sol:=[dsolve(ode)];

The general solution is easy to find since this is just separable. The problem is when I plugin the initial conditions. (again, this is done in a program, without looking at the screen). let consider the first solution above for now.

eq:=simplify(subs( [y(x)=0,x=0],sol[1]));

And here is the problem, when next I try to solve for the constant, Maple says no solution.

solve(eq,_C1,allsolutions=true) assuming _C1::real

No solution returned.

If Maple could return _C1=infinity, then I would plugin _C1=infinity and obtain the correct particular solution which is 

simplify(subs(_C1=infinity,sol[1])) assuming real

Which is what the smart dsolve command does

ode:=diff(y(x),x)=y(x)^3*sin(x);
ic:=y(0)=0;
sol:=dsolve([ode,ic])

I do not know how Maple found the above and what algorithm it used.  

But my not too smart dsolve program gets stuck on such problems, because it can't solve for the IC.

Is there another method or option or assumptions to use, to solve such an equation and request infinity be returned as a solution?  I tried isolate(eq,_C1) but that did not work.  

One possible option to try as a last resource is to do this

limit(eq,_C1=infinity)

And this gives 0=0

which means _C1=infinity is valid solution.  And I could do this as final attempt before giving up. Is this what Maple did? But how does one know to do this in general? Unless one tries and find out? i.e I could try limit(eq,_C1=infinity) and limit(eq,_C1=-infinity) and see if any one of these gives true (after doing  evalb or is  on the output)

Any suggestions or a better/more robust method to use for such cases? I need to use the method for any equation where infinity can be a solution for the constant of integration. It will always be one equation and one variable, and can assume all are real for now if it makes it easier.

 

 

I was wondering why dsolve do not show this one solution I obtained different way, for this ode.

Maple gives 6 solutions to the ODE. But 5 of them are signular (have no constant of integration in them). I am looking at the last solution it gives, the one with constant of integration. 

But when I solve this ODE, after simplifying it, I get different general solution than the last one Maple shows. I thought they might be equivalent, but I do not see how they could be. 

So my question is why Maple did not show the simpler solution also?  Here is the code

ode_orginal:=1/3*(-2*x^(5/2)+3*y(x)^(5/3))/x^(3/2)*diff(y(x),x)/y(x)^(5/3)+1/2*(2*x^(5/2)-3*y(x)^(5/3))/x^(5/2)/y(x)^(2/3) = 0;

This looks complicated and non-linear, but when I solve for y'(x) it gives much simpler and linear ODE (Have to convert the ODE to D before solving for diff(y(x),x), since Maple can complain otherwise).

ode:=convert(ode_orginal,D);
ode:=diff(y(x),x)=solve(ode,D(y)(x),allsolutions=true);

And solving the above gives the much simpler solution

sol:=dsolve(ode,y(x));
odetest(sol,ode);

Now when using dsolve on the original complicated lookin ODE it gives

maple_sol:=[dsolve(ode_orginal)];

if there is any hope that one of the above 6 solutions will be the same as the simpler solution, it has to be the last one, with the _C1 in it, since all the others do not have _C1 (singular solutions).

But solving for y(x) from the last one does not give the simpler solution.

So it is a new general solution for the original ode and it is correct, since odetest gives zero.

I think in the process of solving for y'(x), some solutions got lost. Even though I asked for allsolutions there?.

But my main question is: Should dsolve have also have given the simpler solution? Since that one also satisfies the original nonlinear complicated ode

odetest(sol,ode_orginal);

gives 0.

Maple 2021.1

 

I solved this ode with IC, and obtained a solution.  Maple odetest says my solution satisfies the ODE but not the initial conditions. But I do not see why. When I plugin manually the initial conditions into the solution, I get true.

So I am not sure what is going on.

restart;
ode:=x*diff(y(x),x)*y(x) = (x+1)*(y(x)+1);
ic:=y(1)=1;
mysol:=y(x)-ln(y(x)+1)=-ln(2)+x+ln(x);
my_sol_at_IC:=subs([y(x)=1,x=1],mysol);

#now check manually
evalb(my_sol_at_IC);
is(my_sol_at_IC);

Using odetest gives

odetest(mysol,ode);
odetest(mysol,[ode,ic]);

What Am I doing wrong? 

Maple 2021.1

 

Edit June 12, 2021

This is another example where odetest gives different result depending on how the solution is written !

restart;
ode:=diff(y(x),x)=2/3*(y(x)-1)^(1/2):
mysol_1:=y(x) = 1/9*x^2 - 2/9*x + 10/9:
mysol_2:=y(x) - (1/9*x^2 - 2/9*x + 10/9) = 0 :
odetest(mysol_1,ode);
odetest(mysol_2,ode);

 

First 31 32 33 34 35 36 37 Page 33 of 40