0

The question requires checking of numerical solutions to a differential equation by substituting in those solutions.

The original equation is as follows;

equ = y'[t] - (t^2 y[t]^2)/(1 + 8 t^4)

And the numerical solution for y[t] is calculated as;

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

sol = {{y[t] -> InterpolatingFunction[{{0., 1.5}}, <>][t]}}

I have produced the following pice of code;

Plot[Evaluate[equ /. {y[t] -> sol, y'[t] -> D[sol, t]}], {t, 0., 1.5}]

But it does not produce a graph (it does output the axes) and there is no error message.

If anyone can fix my code, or suggest a better method of substituting in the values for the numerical solution of the equation, I would be very grateful.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Pablo
  • 155
  • 5
  • 1
    Please supply all necessary data/definitons. How do you arrive at sol? – Yves Klett Feb 24 '16 at 17:04
  • 2
    sol = NDSolve[{y'[t] == (t^2 y[t]^2)/(1 + 8 t^4), y[0] == 1/2}, y, {t, 0, 1.5}] (y instead of y[t].) Then, Plot[Evaluate[equ /. sol], {t, 0., 1.5}]. – march Feb 24 '16 at 17:11

2 Answers2

2

Rather than two separate plots, you may prefer a single plot with two differently scaled $y$-axes. To do so, use the function TwoAxisPlot, which is defined on the Documentation Center page howto/GeneratePlotsWithTwoVerticalScales.

Using the definitions of yF and dyF from @m_goldberg's answer:

    TwoAxisPlot[{yF[t], dyF[t]}, {t, 0, 1.5}]

enter image description here

murray
  • 11,888
  • 2
  • 26
  • 50
1

I think the best approach to solving the kind of problem you pose it to structure things to produce pure interpolation functions. To do that proceed as follows:

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

dyF = yF'

Then you can render the two functions on one plot with

Plot[{yF[t], dyF[t]}, {t, 0, 1.5}, AspectRatio -> 1]

one-plot

but I don't think this looks good because the ranges of yF and dyF are so different. Rather I recommend make two plots.

Column[
  {Plot[{yF[t]}, {t, 0, 1.5},
     PlotLabel -> y[t], AspectRatio -> 1, ImageSize -> Medium],
   Plot[{dyF[t]}, {t, 0, 1.5},
     PlotLabel -> y'[t], AspectRatio -> 1, ImageSize -> Medium]},
  Spacings -> 1.5]

two-plots

m_goldberg
  • 107,779
  • 16
  • 103
  • 257