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?
2 Answers
Need to evaluate y[t]
by the solution you've found, not the differential equation!
sol=NDSolve[...]
Plot[Evaluate[y[t]/.sol], ...]
-
$\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$ Mar 4, 2017 at 3:59
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]
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}]