Question: Finding when odetest is zero when csgn appears in solution

sometimes Maple's solution for an ode is not valid for all x. When I run odetest on the solution, it is not zero.

For the case when the output of odetest contains one csgn(), I am trying to determine if odetest result will become zero, when csgn is +1  or -1. If so, then next look into the argument of csgn and solve for x under this condition and hence find the range of x when the solution is valid.

I wrote the following to do this and check the idea.

I'd like to ask if the Maple experts here can suggest improvement or if there a better way to do this.

The code below works if there is only instance of csgn() in the output of odetest. Which covers almost all the cases I saw so far.

The code first checks if csgn is present in the output of odetest. If so, it then uses indents to pick up the function csgn out. Then uses op to pick its argument. Then uses solve with inquality to find when the argument is either positive or negative. This results in the range of x needed to make odetest zero.

This is just a quick prototype to test the idea. This not the final code I will be using as that will include more checks and be more robust. 

restart;
ode :=diff(y(x),x)=2*(x*sqrt(y(x))-1)*y(x):
ic  :=y(0)=1:
sol :=dsolve([ode,ic]):
res :=odetest(sol,ode);

So we see odetest did not give zero.  The issue is that I can't just do 

solve(res=0,x)

It does not work.  So that is why I had to look inside as follows:

The goal is to check if when csgn is either +1 or -1, if it will then become zero.

And if so, then also find the range of x which will caused this.  In the above, we see that when 1/(x+1) is +1, then odetest result  will become zero. This means x has to be larger than -1.

Note that this is all done in code, without being able to look at the screen and then decide what to do

if res<>0 then
    if has(res,csgn) then
        if simplify( subsindets(res,csgn(anything),f->1)) = 0 then      
            print("the odetest becomes zero when csgn is POSITIVE");
            Z:=indets(res,specfunc(csgn));
            the_args:=map(x->op(x),Z);
            print("Now solve ",the_args," for x, when the expression is POSTIVE");
            for tmp in the_args do
                result:=solve(tmp>0,x);
                print("the solution is valid for x>", op([1,1],result));
            od;
        else
            if simplify( subsindets(res,csgn(anything),f->-1)) = 0 then      
                print("the odetest becomes zero when csgn is POSITIVE");
                indets(res,specfunc(csgn));
                the_args:=map(x->op(x),Z);
                print("Now solve ",the_args," for x, when the expression is negative");
                for tmp in the_args do
                    result:=solve(tmp<0,x);
                    print("the solution is valid for x<", op([1,1],result));
                od;
            else
                print("give up. Tried when csgn is positive or negative");
            fi;
        fi;
    fi;
fi;

If there is more than one csgn function in the odetest result, it will become much more complicated, since one have to check all combinations to find under which combination odetest will become zero. So for now, I am just doing this only for one case of csgn present.

 

Please Wait...