# Verifying the solution of a numerically solved ODE [duplicate]

I am solving this equation;

DSolve[{y'[t] == (t^2 y[t]^2)/(1 + 8 t^4), y[0] == 1/2}, y[t], t]
NDSolve[{y'[t] == (t^2 y[t]^2)/(1 + 8 t^4), y[0] == 1/2}, y, {t, 0, 1.3}]


I have solved it numerically and analytically and I have plotted both results.

I need to check my solutions by substituting them back into the original equation; I am not sure how to do this, specifically for the numerical solution.

• You shouldn't use the orginal equation to check the steps of numerical solution, since the original equation is used to compute the derivative. The error in y could be huge while the error in the ODE should still be close to zero. Checking between the steps will add a significant interpolation error, unless you use the option InterpolationOrder -> All in NDSolve. Mar 3, 2020 at 3:52

An other way.

dsol = DSolve[{y'[t] == (t^2 y[t]^2)/(1 + 8 t^4), y[0] == 1/2}, y, t]
ndsol = NDSolve[{y'[t] == (t^2 y[t]^2)/(1 + 8 t^4), y[0] == 1/2}, y, {t, 0, 1.3}, InterpolationOrder -> All]

{eq, ic} = {y'[t] == (t^2 y[t]^2)/(1 + 8 t^4), y[0] == 1/2};

Plot[(y[t] /. First@dsol) - (y[t] /. First@ndsol), {t, 0, 1.3},
PlotRange -> All]

ic /. First@ndsol // Simplify

(*   True   *)

Plot[eq[[1]] - eq[[2]] /. First@ndsol, {t, 0, 1.3},
PlotRange -> All]


Something like this?

sol1 = y[t] /. DSolve[{y'[t] == (t^2 y[t]^2)/(1 + 8 t^4), y[0] == 1/2}, y[t], t]
sol2 = y[t] /. NDSolve[{y'[t] == (t^2 y[t]^2)/(1 + 8 t^4), y[0] == 1/2}, y, {t, 0, 1.3}]

Plot[{Abs[sol1 - sol2]}, {t, 0, 1.3}]