1
$\begingroup$

Working through some problems of the book A Physicists guide to Mathematica. I'm getting the following errors when I try and plot the solution over a certain range. Any ideas?

enter image description here

$\endgroup$
  • 2
    $\begingroup$ Also include copy-able code in your question. $\endgroup$ – zhk Mar 4 '17 at 4:21
4
$\begingroup$

Need to evaluate y[t] by the solution you've found, not the differential equation!

sol=NDSolve[...]

Plot[Evaluate[y[t]/.sol], ...]
$\endgroup$
  • $\begingroup$ Of course!!! Time for a coffee... I was wondering why I was getting these errors... I had gone through multiple this morning and getting great results! I will accept once it allows me. $\endgroup$ – Rumplestillskin Mar 4 '17 at 3:59
3
$\begingroup$

You need to check the help page on NDSolve.

The interpolation function and its derivative can be plotted like this,

eqn = y''[t] == Sin[t]*y[t] + t

sol = NDSolve[{eqn, y[0] == 0, y'[0] == 1}, y, {t, 0, 10}]

Plot[Evaluate[{y[t], y'[t]} /. sol], {t, 0, 10}, Frame -> True]

enter image description here

If you need, then you can also plot y[t] vs y'[t] using ParametricPlot,

ParametricPlot[Evaluate[{y[t], y'[t]} /. First[sol]], {t, 0, 10}]

enter image description here

$\endgroup$

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