0
$\begingroup$

I'm working on a simulation where I've got a list of points (i.e. {{0, 0}, {1, 1}, ... , {10, 10}}). I'm trying to graph a differential equation on the same axes as the list of points. I know I have to Plot NDSolve to plot the differential equation and ListPlot on the list of points. How would I do both?

Let me know if you need more information. Thanks!

$\endgroup$

1 Answer 1

3
$\begingroup$

Next time, share complete information (DE's and data points).

Are you looking for something like this?

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

p1 = Plot[y[t] /. sol, {t, 0, 1}];

points = Table[{t, N@Exp[t]}, {t, 0, 1, 0.5}];

p2 = ListPlot[points, PlotStyle -> Red];

Show[{p1, p2}]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Or just add the points to the Plot usingEpilog, e.g., Plot[y[t] /. sol, {t, 0, 1}, Epilog -> {Red, AbsolutePointSize[4], Point[points]}] $\endgroup$
    – Bob Hanlon
    Commented Apr 18, 2018 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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