# What is the correct way to verify solutions from different ode symbolic solvers against each others?

I am not a math major, so I thought to check with the experts here on this.

Given some ODE $y'(x)=f(y,x)$ solved by CAS system A which gives answer $y_1(x)$. Same ODE solved by CAS system B with answer $y_2(x)$.

Since the ODE does not involve initial conditions, Answers will contain constant(s) of integration. Lets say there is one constant of integration $C_0$ for now. (it was a first order ODE)

To verify that $y_1(x)$ is the same as $y_2(x)$, both solutions are plotted over some small range of $x$ around the origin to see if the solutions are the same.

Since there is a constant of integration, it is given some constant value, say the number $1$ in order just to be able to make a plot.

Is this a valid approach? Some of the answers are too complicated to visually verify the expressions are equivalent. But sometimes the solutions to the same ODE do not come up the same in the plot. There remains some difference. That is why I am asking here, if there is a better way to do this.

To make things more clear, an example below is given, with the solution from Maple and Mathematica. Both involve one constant of integration. Using $C_0=1$ the plots of the solutions are generated. Yet we see the plots of $y(x)$ are not exactly the same. There is still a shift involved. (The method has to be numerical, as it is simpler for quick verification).

the ODE is Kamke's #131 given by $\left( 1+2x\right) y^{\prime}\left( x\right) +2-4e^{-y\left( x\right) }=0$

## The ODE is in Mathematica syntax:

Clear["Global*"];
ode131 = (2*x + 1)*D[y[x], x] - 4*Exp[-y[x]] + 2 == 0
DSolve[%, y[x], x]


which gives

{{y[x] -> Log[2 - E^C[1]/(1 + 2*x)]}}


## In Maple 16

restart;
ode131:=(1+2*x)*diff(y(x),x)+2-4*exp(-y(x))=0:
dsolve(%,y(x));


which gives

y(x) = -ln((1+2*x)/(-1+2*exp(2*_C1)+4*x*exp(2*_C1)))-2*_C1


Here is a plot of both solutions next to each others. We see the shift. Actually using different numerical value for the constant of integration, makes the solutions even more different looking. This is with $C_0=1$

(ps. Log is natural log in Mathematica)

FYI, the equation from the book (it is written in German) and solution is

update

Using suggestion below by Mhenni Benghorbal, Maple says both solutions are the same:

ode := (2*x+1)*diff(y(x),x)-4*exp(-y(x))+2:
mapleSol := dsolve( ode ):
odetest( mapleSol, ode );
0


and

mathematicaSol:=y(x)=ln(2 - (exp^_C1)/(1 + 2*x)):
odetest( mathematicaSol, ode );
0


So the answers the same. I'd still like to know if possible from Mathematics point of view why just plugging the same constant in the solutions and plotting the resulting function do not show the same shapes.

-
Try to ask at stackoverflow.com as well, Nasser. – Babak S. Dec 5 '12 at 9:28

In maple, you can run the "odetest" command, for example

ode := (2*x+1)*diff(y(x),x)-4*exp(-y(x))+2;

sol := dsolve( ode );

odetest( sol, ode );

If the function satisfies the ode then "odetest" returns $0$. So you can take mathematica answer and write in the maple worksheet and run the "odetest" and see what you get.

-
Thanks, that is useful. I just did , please see edit. I get 0` for both answers. – Nasser Dec 5 '12 at 10:12
@NasserM.Abbasi: Constants are determined by the initial conditions. – Mhenni Benghorbal Dec 5 '12 at 10:17
@NasserM.Abbasi: Since you have two different forms of solutions, then you need to relate the constants in the two solutions first. – Mhenni Benghorbal Dec 5 '12 at 10:20