odetest
test the explicit or implicit results from ODE-solvers
Calling Sequence
Parameters
Description
Examples
odetest(sol, ODE, y(x))
odetest(sol, ODE, series, point=x0)
sol
-
Ordinary Differential Equation (ODE) solution being tested; can be a set or list of them
ODE
ODE, or a set or list of them which can also include initial or boundary conditions
y(x)
(optional) indeterminate function of the ODE or a set or list of them
series
required when testing series solutions
point=x0
(optional) specification of the expansion point, x0, when testing series solutions
The odetest command checks explicit and implicit solutions for ODEs by making a careful simplification of the ODE with respect to the given solution. If the solution is valid, the returned result will be 0; otherwise, the algebraic remaining expression will be returned. In the case of systems of ODEs, odetest can only test explicit solutions, given either as a set or as a list of sets. (For information on non-composed sets of solutions for nonlinear systems, see dsolve,system.)
To test whether a solution satisfies one or many initial or boundary conditions, pass to odetest the ODE together with the initial or boundary conditions, enclosed as a set or list, as second argument.
If odetest returns a nonzero result, the solution being tested is not necessarily wrong; sometimes further simplifications or manipulations of odetest's output are required to obtain zero, and so verify the solution is correct. If the solution was obtained using the dsolve command, it is recommended that you recompute the solution using one or both of the useInt and implicit options - see dsolve. This may facilitate the verification process. Also, an alternative testing technique, particularly useful with linear ODEs, is to try to recompute the ODE departing from the solution which odetest fails in testing. Examples of both types are found at the end of the next section.
To test series solutions, pass the keyword series as an extra argument. Only one series solution for one ODE (can be a set with initial/boundary conditions) can be tested.
An ODE problem with initial conditions
ODE≔diff⁡y⁡x,x=sin⁡x−y⁡x,y⁡0=8
ODE≔ⅆⅆxy⁡x=sin⁡x−y⁡x,y⁡0=8
sol≔dsolve⁡ODE
sol≔y⁡x=x−2⁢arctan⁡tan⁡4⁢x−2⁢tan⁡4+xtan⁡4⁢x+x+2+2⁢π
odetest⁡sol,ODE
0,0
A second order ODE problem with boundary conditions
ODE≔diff⁡y⁡x,x,x+diff⁡y⁡x,x+y⁡x=0
ODE≔ⅆ2ⅆx2y⁡x+ⅆⅆxy⁡x+y⁡x=0
bc≔y⁡0=1,y⁡2⁢π=1
sol≔dsolve⁡ODE,bc
sol≔y⁡x=ⅇ−x2⁢csc⁡3⁢π⁢ⅇπ−cot⁡3⁢π⁢sin⁡3⁢x2+cos⁡3⁢x2
odetest⁡sol,ODE,bc
0,0,0
A series solution for a nonlinear ODE with initial conditions
ODE≔diff⁡y⁡x,x,x+diff⁡y⁡x,x2=0,y⁡a=0,D⁡y⁡a=1
ODE≔ⅆ2ⅆx2y⁡x+ⅆⅆxy⁡x2=0,y⁡a=0,D⁡y⁡a=1
sol≔dsolve⁡ODE,y⁡x,type=series
sol≔y⁡x=x−a−12⁢x−a2+13⁢x−a3−14⁢x−a4+15⁢x−a5+O⁡x−a6
odetest⁡sol,ODE,series
When testing series solutions and the initial conditions are not present in the input to odetest, an indication of the expansion point is required
ODE≔diff⁡diff⁡y⁡x,x,x=3⁢x2+c⁢diff⁡y⁡x,x+3−b⁢x−a⁢y⁡x
ODE≔ⅆ2ⅆx2y⁡x=3⁢x2+c⁢ⅆⅆxy⁡x+3−b⁢x−a⁢y⁡x
sol≔y⁡x=series⁡1+−12⁢a⁢x2+−16⁢b+12−16⁢c⁢a⁢x3+124⁢a2−124⁢c⁢b+18⁢c−124⁢c2⁢a⁢x4+O⁡x5,x,5
sol≔y⁡x=1−12⁢a⁢x2+−b6+12−c⁢a6⁢x3+124⁢a2−124⁢c⁢b+18⁢c−124⁢c2⁢a⁢x4+O⁡x5
odetest⁡sol,ODE,series,point=0
0
An ODE with an arbitrary function _F1 of (x, y, dy/dx) and a solution involving nested integrals with a RootOf in the integrand
ODE≔diff⁡y⁡x,x,x=1x2⁢_F1⁡diff⁡y⁡x,x⁢xy⁡x⁢y⁡x
ODE≔ⅆ2ⅆx2y⁡x=_F1⁡ⅆⅆxy⁡x⁢xy⁡x⁢y⁡xx2
sol≔y⁡x=ⅇ∫` `ln⁡xRootOf⁡∫` `_Z1_a−_a2+_F1⁡_aⅆ_a−_b+c__1ⅆ_b+c__2
Testing ODE solutions given in implicit form, that is, not solved for the unknown (here y(x))
ODE≔diff⁡y⁡x,x=F⁡y⁡x−x⁢ln⁡xx+ln⁡x
ODE≔ⅆⅆxy⁡x=F⁡y⁡x−x⁢ln⁡xx+ln⁡x
sol≔dsolve⁡ODE,implicit
sol≔ln⁡x−∫` `−ln⁡x+y⁡xx1−1+F⁡_a−_aⅆ_a−c__1=0
When the ODE has derivatives of other indeterminate functions and the solution is implicit, the specification of the indeterminate function of the problem is required by both dsolve and odetest
ODE≔diff⁡y⁡x,x=x⁢f⁡x2⁢x+2⁢y⁡x3+f⁡x⁢x+3⁢y⁡x2−diff⁡f⁡x,xf⁡x⁢y⁡x
ODE≔ⅆⅆxy⁡x=x⁢f⁡x2⁢x+2⁢y⁡x3+f⁡x⁢x+3⁢y⁡x2−ⅆⅆxf⁡x⁢y⁡xf⁡x
sol≔dsolve⁡ODE,y⁡x,implicit
sol≔c__1+arctanh⁡f⁡x⁢y⁡x⁢xx⁢f⁡x⁢y⁡x⁢x+2+2+x⁢f⁡x⁢y⁡x⁢x+2+22⁢f⁡x⁢y⁡x=0
odetest⁡sol,ODE,y⁡x
Testing reductions of order returned by dsolve using ODESolStructures
ODE≔diff⁡y⁡x,x,x=diff⁡y⁡x,x−y⁡x3−f⁡x+3⁢x⁢y⁡x2⁢diff⁡y⁡x,x+x⁢diff⁡f⁡x,xx
ODE≔ⅆ2ⅆx2y⁡x=ⅆⅆxy⁡x−y⁡x3−f⁡x+3⁢x⁢y⁡x2⁢ⅆⅆxy⁡x+ⅆⅆxf⁡x⁢xx
sol≔dsolve⁡ODE,y⁡x
sol≔y⁡x=_b⁡_awhereⅆⅆ_a_b⁡_a_a−_b⁡_a3−c__1⁢_a+f⁡_a_a=0,_a=x,_b⁡_a=y⁡x,x=_a,y⁡x=_b⁡_a
A linear system of ODEs. The solution is a set containing x(t) and y(t) as functions of t.
sysODE≔diff⁡x⁡t,t=y⁡t,diff⁡y⁡t,t=−x⁡t,x,y⁡t
sysODE≔ⅆⅆtx⁡t=y⁡t,ⅆⅆty⁡t=−x⁡t,x⁡t,y⁡t
solsys≔dsolve⁡sysODE
solsys≔x⁡t=c__1⁢sin⁡t+c__2⁢cos⁡t,y⁡t=c__1⁢cos⁡t−c__2⁢sin⁡t
odetest⁡solsys,sysODE
A nonlinear system of ODEs. The solution is a list of sets, the first one containing the possible answers for x(t), and the second one expressing y(t) as a function of x(t):
sysODE≔diff⁡x⁡t,t=y⁡t,diff⁡y⁡t,t=−x⁡t2,x,y⁡t
sysODE≔ⅆⅆtx⁡t=y⁡t,ⅆⅆty⁡t=−x⁡t2,x⁡t,y⁡t
solsys≔x⁡t=−6⁢WeierstrassP⁡t+c__1,0,c__2,y⁡t=ⅆⅆtx⁡t
These answers can be tests by passing them to odetest as a list.
Alternatively, you can call dsolve with the 'explicit' extra argument to directly obtain (many) composed solution sets. To test all these answers, use the map function to apply odetest to each solution set:
solsys≔dsolve⁡sysODE,explicit
solsys≔x⁡t=−6⁢WeierstrassP⁡t+c__1,0,c__2,y⁡t=−6⁢WeierstrassPPrime⁡t+c__1,0,c__2
map⁡odetest,solsys,sysODE
One possible workaround for an example where odetest fails in verifying dsolve's solution
ODE≔diff⁡y⁡t,t=b+2+2⁢t⁢y⁡t+11−1+t2
ODE≔ⅆⅆty⁡t=b+2+2⁢t⁢y⁡t+11−1+t2
sol≔y⁡t=−22−b2⁢tb2+1⁢hypergeom⁡b2,b2+1,2+b2,−t22⁢b+2+c__1⁢t+2b2−1⁢t−b2−1
−−1+t2b2⁢hypergeom⁡b2+1,b2+1,2+b2,−t2⁢b⁢t+2⁢hypergeom⁡b2,b2,b2+1,−t2⁢b⁢1+t2b2+4⁢1+t2b2⁢hypergeom⁡b2,b2,b2+1,−t2−2⁢b−4⁢b+t⁢b+2+t2⁢t+22⁢t2⁢b+2
sol2≔dsolve⁡ODE,useInt
sol2≔y⁡t=∫−ⅇ∫b+2+2⁢tt⁢t+2ⅆtt⁢t+2ⅆt+c__1⁢ⅇ∫−b+2+2⁢tt⁢t+2ⅆt
odetest⁡sol2,ODE
By evaluating the integrals appearing in sol2, the output returned by dsolve without using the 'useInt' option can be constructed from the one obtained using the 'useInt' option, which was already verified to be correct.
An example hard to test due to the presence of radicals and Kummer functions in the solution
ODE≔diff⁡y⁡x,`$`⁡x,2=−a1⁢F+a0⁢E⁢x+B⁢e⁢a1⁢y⁡xB2⁢e2⁢x⁢E3
ODE≔ⅆ2ⅆx2y⁡x=a0⁢E−a1⁢F⁢x+B⁢e⁢a1⁢y⁡xB2⁢e2⁢x⁢E3
sol≔dsolve⁡ODE,hyper3
sol≔y⁡x=c__1⁢ⅇ−a0⁢E−a1⁢F⁢xB⁢e⁢E32⁢x⁢hypergeom⁡2⁢a0⁢E−a1⁢F⁢E32+a12⁢a0⁢E−a1⁢F⁢E32,2,2⁢a0⁢E−a1⁢F⁢xB⁢e⁢E32+c__2⁢ⅇ−a0⁢E−a1⁢F⁢xB⁢e⁢E32⁢x⁢KummerU⁡2⁢a0⁢E−a1⁢F⁢E32+a12⁢a0⁢E−a1⁢F⁢E32,2,2⁢a0⁢E−a1⁢F⁢xB⁢e⁢E32
ode≔PDEtoolsdpolyform⁡sol,no_Fn
ode≔ⅆ2ⅆx2y⁡x=B⁢e⁢a1+E⁢x⁢a0−F⁢x⁢a1⁢y⁡xB2⁢e2⁢x⁢E3where
normal⁡ODE−op⁡1,1,ode
0=0
Yet another alternative is to convert the special functions entering sol to other functions easier to test; in this example convert from Kummer to Whittaker functions:
sol_W≔convert⁡sol,Whittaker
sol_W≔y⁡x=−c__1⁢WhittakerM⁡−1,12,−a0⁢E−a1⁢F⁢xB⁢e⁢E32⁢B2⁢e2⁢E3⁢WhittakerM⁡−a12⁢a0⁢E−a1⁢F⁢E32,12,2⁢a0⁢E−a1⁢F⁢xB⁢e⁢E32⁢ⅇa0⁢E−a1⁢F⁢xB⁢e⁢E322⁢ⅇa0⁢E−a1⁢F⁢x2⁢B⁢e⁢E32⁢a0⁢E−a1⁢F⁢x−c__2⁢WhittakerM⁡−1,12,−a0⁢E−a1⁢F⁢xB⁢e⁢E32⁢B2⁢e2⁢E3⁢WhittakerW⁡−a12⁢a0⁢E−a1⁢F⁢E32,12,2⁢a0⁢E−a1⁢F⁢xB⁢e⁢E32⁢ⅇa0⁢E−a1⁢F⁢xB⁢e⁢E322⁢ⅇa0⁢E−a1⁢F⁢x2⁢B⁢e⁢E32⁢a0⁢E−a1⁢F⁢x
odetest⁡sol_W,ODE
See Also
DEtools
dsolve
dsolve,system
odeadvisor
pdetest
symgen
symtest
Download Help Document