2
$\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$
1
  • 2
    $\begingroup$ Also include copy-able code in your question. $\endgroup$
    – zhk
    Commented Mar 4, 2017 at 4:21

2 Answers 2

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$
1
  • $\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$ Commented Mar 4, 2017 at 3:59
4
$\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.