Question: A good way to check for result from odetest()?

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

Please Wait...