Context: I'm trying to plot a phase-space orbit. After struggling for a good long while, I realized that I could solve the x differential equation analytically, rather than relying on NDSolve, and was able to plot the orbit. But I'm still wondering why the output of NDSolve wouldn't work in ParametricPlot even though it did in Plot. Hence, pretending I can't solve the equation analytically....

The equation for my p-axis (i.e. the y-axis) is just a linear equation in t, -m*g*t. I used NDSolve to get the equation for my x-axis.

xA = NDSolve[{a'[t]== l*g*t^2 - (g + 2*l*pA/m)*t + (pA/m + l*pA^2/m^2/g), a[0] == .1}, 
a, {t, 0, 15}]

I can plot xA versus time in Plot.

Plot[{a[t] /. xA}, {t, 0, .5}]

(I get the same graph if I replace a[t] /. xA with the analytic solution).

However, when I try to do

ParametricPlot[{a[t] /. xA, -m*g*t}, {t, 0, .5}]

I get nothin' but a blank graph. (Whereas I get a curve if I replace a[t] /. xA with the analytic solution.)

Why can't ParametricPlot figure it out when Plot is on top of the game? How can you use the results of NDSolve in ParametricPlot?

  • 1
    xA is a list, you need to extract the first part: ParametricPlot[{a[t] /. xA[[1]], -m*g*t}, {t, 0, .5}] – Chris K Jan 22 '17 at 1:18

You just need to write First@NDSolve,

l = 1; g = 1; m = 1; pA = 1;
xA = First@
  NDSolve[{a'[t] == 
     l*g*t^2 - (g + 2*l*pA/m)*t + (pA/m + l*pA^2/m^2/g), a[0] == .1}, 
   a, {t, 0, 15}]
ParametricPlot[{a[t] /. xA, -m*g*t}, {t, 0, .5}]

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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