5
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Michael E2
    Mar 3, 2020 at 3:52

2 Answers 2

6
$\begingroup$

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]
$\endgroup$
5
$\begingroup$

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}]
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.