nm

11353 Reputation

20 Badges

13 years, 20 days

MaplePrimes Activity


These are questions asked by nm

In answers given in 

In https://www.mapleprimes.com/questions/227546-How-To-Make-Odetest-Verify-Dsolve

It shows that odetest() did not verify a solution to ODE becuase solution was using hypergeom special functions. If the solution to the ODE was in integral form, then odetest() will verify it OK.

But what to do if the solution I want to verify is already in hypergoem? If I try odetest() it will fail to verify now. Then I can try to convert the solution to integral form and try again.

But when  using convert(sol,Int) followed by odetest() it did not work.

The solutions I try to verify are hand solutions or book solutions, and not coming from dsolve. 

But some of them are the same solution that comes from dsolve() when not using the useInt option. 

Also, I am doing this all inside a Maple program. It is not an interactive process. So I can't do plots and look at them to decide on anything. So verification must all be implemented in code.

The question is: Why did convert(hand_solution,Int) not give the same result as dsolve(ode,useInt)? Is there another way around this? (May be I am asking for too much in this one based on answers in the above link, So that is OK if not possible. But I really like the solution given when using "useInt" option. Much more clear than otherwise).
 

restart;

ode := diff(y(x), x)*(x^3 + 1)^(2/3) + (1 + y(x)^3)^(2/3) = 0;
sol_int:=dsolve(ode,useInt);
odetest(sol_int,ode); #OK now, since solution in integral form

(diff(y(x), x))*(x^3+1)^(2/3)+(1+y(x)^3)^(2/3) = 0

Int(1/(x^3+1)^(2/3), x)+Intat(1/(_a^3+1)^(2/3), _a = y(x))+_C1 = 0

0

hand_solution:= x*hypergeom([1/3, 2/3], [4/3], -x^3) + y(x)*hypergeom([1/3, 2/3], [4/3], -y(x)^3) + _C1 = 0;
convert(hand_solution,Int); #Why this did not give same result as ABOVE?

x*hypergeom([1/3, 2/3], [4/3], -x^3)+y(x)*hypergeom([1/3, 2/3], [4/3], -y(x)^3)+_C1 = 0

(2/9)*x*Pi*3^(1/2)*(Int(1/(_t1^(1/3)*(1-_t1)^(1/3)*(x^3*_t1+1)^(1/3)), _t1 = 0 .. 1))/GAMMA(2/3)^3+(2/9)*y(x)*Pi*3^(1/2)*(Int(1/(_t1^(1/3)*(1-_t1)^(1/3)*(y(x)^3*_t1+1)^(1/3)), _t1 = 0 .. 1))/GAMMA(2/3)^3+_C1 = 0

odetest(%,ode); #does not give zero

-y(x)^3*(1+y(x)^3)^(2/3)*(Int(_t1^(2/3)/((1-_t1)^(1/3)*(y(x)^3*_t1+1)^(4/3)), _t1 = 0 .. 1))+(x^3+1)^(2/3)*(Int(_t1^(2/3)/((1-_t1)^(1/3)*(x^3*_t1+1)^(4/3)), _t1 = 0 .. 1))*x^3-(x^3+1)^(2/3)*(Int(1/(_t1^(1/3)*(1-_t1)^(1/3)*(x^3*_t1+1)^(1/3)), _t1 = 0 .. 1))+(1+y(x)^3)^(2/3)*(Int(1/(_t1^(1/3)*(1-_t1)^(1/3)*(y(x)^3*_t1+1)^(1/3)), _t1 = 0 .. 1))

 

 

Maple 2019.1

Download 072619_2.mw

 

 

 

THis is another ode which I am not able to get odetest to give zero. Any one knows of a trick to verify this solution? It might be just that the solution is too complicated for odetest to verify?


 

restart;

ode:=diff(y(x),x)*(x^3+1)^(2/3)+(1+y(x)^3)^(2/3) = 0;
sol:=dsolve(ode);

(diff(y(x), x))*(x^3+1)^(2/3)+(1+y(x)^3)^(2/3) = 0

x*hypergeom([1/3, 2/3], [4/3], -x^3)+y(x)*hypergeom([1/3, 2/3], [4/3], -y(x)^3)+_C1 = 0

odetest(sol,ode);

-9*(1+y(x)^3)^(1/3)*(x^3+1)^(2/3)*hypergeom([4/3, 5/3], [7/3], -x^3)*x^3*GAMMA(2/3)*(-y(x)^3)^(1/6)/(9*hypergeom([4/3, 5/3], [7/3], -y(x)^3)*y(x)^3*(-y(x)^3)^(1/6)*(1+y(x)^3)^(1/3)*GAMMA(2/3)-4*Pi*3^(1/2)*LegendreP(-1/3, -1/3, -y(x)^3/(1+y(x)^3)+1/(1+y(x)^3)))+9*y(x)^6*hypergeom([4/3, 5/3], [7/3], -y(x)^3)*GAMMA(2/3)*(-y(x)^3)^(1/6)/(9*hypergeom([4/3, 5/3], [7/3], -y(x)^3)*y(x)^3*(-y(x)^3)^(1/6)*(1+y(x)^3)^(1/3)*GAMMA(2/3)-4*Pi*3^(1/2)*LegendreP(-1/3, -1/3, -y(x)^3/(1+y(x)^3)+1/(1+y(x)^3)))+9*y(x)^3*hypergeom([4/3, 5/3], [7/3], -y(x)^3)*GAMMA(2/3)*(-y(x)^3)^(1/6)/(9*hypergeom([4/3, 5/3], [7/3], -y(x)^3)*y(x)^3*(-y(x)^3)^(1/6)*(1+y(x)^3)^(1/3)*GAMMA(2/3)-4*Pi*3^(1/2)*LegendreP(-1/3, -1/3, -y(x)^3/(1+y(x)^3)+1/(1+y(x)^3)))-4*(1+y(x)^3)^(2/3)*Pi*3^(1/2)*LegendreP(-1/3, -1/3, -(y(x)^3-1)/(1+y(x)^3))/(9*hypergeom([4/3, 5/3], [7/3], -y(x)^3)*y(x)^3*(-y(x)^3)^(1/6)*(1+y(x)^3)^(1/3)*GAMMA(2/3)-4*Pi*3^(1/2)*LegendreP(-1/3, -1/3, -y(x)^3/(1+y(x)^3)+1/(1+y(x)^3)))+4*(1+y(x)^3)^(1/3)*(x^3+1)^(1/3)*Pi*3^(1/2)*LegendreP(-1/3, -1/3, -(x^3-1)/(x^3+1))*(-y(x)^3)^(1/6)/((-x^3)^(1/6)*(9*hypergeom([4/3, 5/3], [7/3], -y(x)^3)*y(x)^3*(-y(x)^3)^(1/6)*(1+y(x)^3)^(1/3)*GAMMA(2/3)-4*Pi*3^(1/2)*LegendreP(-1/3, -1/3, -y(x)^3/(1+y(x)^3)+1/(1+y(x)^3))))

simplify(%);

-9*((4/9)*(1+y(x)^3)^(2/3)*Pi*3^(1/2)*LegendreP(-1/3, -1/3, (-y(x)^3+1)/(1+y(x)^3))*(-x^3)^(1/6)+(-(4/9)*(1+y(x)^3)^(1/3)*(x^3+1)^(1/3)*Pi*3^(1/2)*LegendreP(-1/3, -1/3, (-x^3+1)/(x^3+1))+(-x^3)^(1/6)*((-y(x)^6-y(x)^3)*hypergeom([4/3, 5/3], [7/3], -y(x)^3)+x^3*(1+y(x)^3)^(1/3)*hypergeom([4/3, 5/3], [7/3], -x^3)*(x^3+1)^(2/3))*GAMMA(2/3))*(-y(x)^3)^(1/6))/((-x^3)^(1/6)*(9*hypergeom([4/3, 5/3], [7/3], -y(x)^3)*y(x)^3*(-y(x)^3)^(1/6)*(1+y(x)^3)^(1/3)*GAMMA(2/3)-4*Pi*3^(1/2)*LegendreP(-1/3, -1/3, (-y(x)^3+1)/(1+y(x)^3))))

 


 

Download 072619.mw

Maple 2019.1, Physics 395

Download 072619.mw

 

 

I have been using simplify() in number of places, and not really expecting it will do any harm. At worst, it will have no effect, or it will change the expression to different form, but the semantics will remain the same.

Until I noticed that odetest() fail on some of my solutions because I called simplify  on the solution before.

One example why this happens, is that Maple simplifies cos(2*x)*sqrt(1/cos(2*x)^2) to csgn(1/cos(2*x)) and this makes odetest fail. Adding assuming x::real has no effect on making odetest happy.

So now I changed simplify(sol) to simplify(sol,size) and this seems so far not to have this adverse effect. 

My main reason for calling simplify  is to make the expression smaller. In Mathematica that is what I do, In Mathematica there is no "size" option to Simplify.

So now, I am very worried about calling simplify() as is.

Could some Maple experts share some of their experience on this? Should one call simplify() only when an explicit option, like size, trig, exp, etc....is also used and not call simplify as is?

restart;

ode:= diff(y(x),x) = 2+2*sec(2*x)+2*y(x)*tan(2*x);
my_sol:= y(x) = ((2*x+sin(2*x))/(cos(2*x)*sqrt(1/cos(2*x)^2))+_C1)*sqrt(1+tan(2*x)^2);
odetest(my_sol,ode);

diff(y(x), x) = 2+2*sec(2*x)+2*y(x)*tan(2*x)

y(x) = ((2*x+sin(2*x))/(cos(2*x)*(1/cos(2*x)^2)^(1/2))+_C1)*(1+tan(2*x)^2)^(1/2)

0

#now simplify the solution first
simplify(my_sol);
odetest(%,ode);

y(x) = (_C1*csgn(1/cos(2*x))+sin(2*x)+2*x)/cos(2*x)

csgn(1, 1/cos(2*x))*_C1/cos(2*x)

simplify(my_sol) assuming x::real;
odetest(%,ode);

y(x) = (_C1*signum(cos(2*x))+sin(2*x)+2*x)/cos(2*x)

signum(1, cos(2*x))*_C1/cos(2*x)

simplify(my_sol,size);
odetest(%,ode);

y(x) = ((2*x+sin(2*x))/(cos(2*x)*(1/cos(2*x)^2)^(1/2))+_C1)*(1+tan(2*x)^2)^(1/2)

0

simplify(cos(2*x)*sqrt(1/cos(2*x)^2))

csgn(1/cos(2*x))

 

 

Download 072519.mw

 

 

Most of the time, odetest() returns just zero if solution satisfies ode, and non-zero expression if solution does not satisfy ode.

So I was just checking for zero as return value to check if my solution was verified or not. This works for most cases.

But there are cases when odetest returns odetest/PIECEWISE` where some cases are zero and some are not.  Example is below.

For this, I still want to consider my solution as valid if one of the cases in piecwise is zero. But I am not sure what is a robust way to do this in code. Currently, I do the following

restart;
ode:=x*diff(y(x),x) = y(x)+2*(x*y(x))^(1/2);
my_sol:=y(x)=x*(ln(x/_C1)^2 - 1) - 2*(-1 + sqrt(ln(x/_C1)^2))*x;
res:=odetest(my_sol,ode);
if res<>0 then
   if type(res,'function') then #this meant to handle PIECWISE                      
      print("verified");
   else
      print("did not verify");
   fi;
else #if we come here, res=0, so I am sure it is valid.
   print("verified");
fi;

In the above, the check  type(res,'function')  is meant to catch PIECEWISE  return, since when I did type(res) Maple told me the type is function.

But I am not sure if this is a robust way to check for this, as it might be possible maple will return non zero, and also a function, but it will not be what I think it is (i.e. PIECEWISE) and then I would flag my solution as valid when it is not.

worksheet attached also.


 

restart;
ode:=x*diff(y(x),x) = y(x)+2*(x*y(x))^(1/2);
my_sol:=y(x)=x*(ln(x/_C1)^2 - 1) - 2*(-1 + sqrt(ln(x/_C1)^2))*x;
res:=odetest(my_sol,ode);
if res<>0 then
   if type(res,'function') then
      print("verified");
   else
      print("did not verify");
   fi;
else
   print("verified");
fi;

ode := x*(diff(y(x), x)) = y(x)+2*sqrt(x*y(x))

my_sol := y(x) = x*(ln(x/_C1)^2-1)-(2*(-1+sqrt(ln(x/_C1)^2)))*x

`odetest/PIECEWISE`([0, x/exp((-x+(x*y(x))^(1/2))/x) = _C1], [0, x/exp((x+(x*y(x))^(1/2))/x) = _C1], [-4*(-x^2*(-ln(x/_C1)^2+2*(ln(x/_C1)^2)^(1/2)-1))^(1/2), x/exp(-(-x+(x*y(x))^(1/2))/x) = _C1], [-4*(-x^2*(-ln(x/_C1)^2+2*(ln(x/_C1)^2)^(1/2)-1))^(1/2), x/exp(-(x+(x*y(x))^(1/2))/x) = _C1])

"verified"

 

 

Download how_to_check_odetest.mw

I use patmatch to look for certain expression inside a larger expression.

I find sometimes I need to repeat the same code to check for  "... + ..."   and also ".... * .....", since I do not know to tell Maple to look for + or * in the same code. *Luckily, I do not have to check for "-" or "/" operators, since "+" match with "-" and "*" match with "/").

An example will make things more clear.

Suppose I want to see if sin(x)*sqrt(x*y) has sqrt(x*y) anywhere in it. So I first try

restart;
expr:= sin(x)*sqrt(x*y);
if patmatch(expr,a::anything+(b::anything*x*y)^(c::anything),'la') then
    assign(la);
    if c =1/2 or c=-1/2 then
       print("found sqrt(x*y)");
    else
       print("did not find sqrt(x*y)");
    fi;
 else
   print("did not find sqrt(x*y)");
 fi;

And this fails, since I used "+" inside the patmatch. Then I try '*" instead

if patmatch(expr,a::anything*(b::anything*x*y)^(c::anything),'la') then

And now it does match.

What I'd like to write, is something like this (which ofcourse does not work)

if patmatch(expr,a::anything (* or +) (b::anything*x*y)^(c::anything),'la') then

I looked at conditional in patmatch, but it does not seem to apply for the above.

Any suggestions?

Maple 2019.1 on windows 10

 

First 139 140 141 142 143 144 145 Last Page 141 of 199