Message Boards Message Boards

Empty Plot of NDSolve output

Posted 1 year ago

Hi all, I am quite new to Mathematica and have no idea what is wrong with my code. The code looks like the following:

m = 1
L = 1
a = Pi/4
o = 10
s = NDSolve[{m*r''[t] == -m*9.81*Cos[a]*Sin[a] + 
     L^2/(m*r[t]^3)*Power[Sin[a], 2], r[0] == 2, r'[0] == 0}, 
  r, {t, 0, o}]
n = NDSolve[{m*Evaluate[r[t] /. s]*p'[t] == L, p[0] == 0}, 
  p, {t, 0, o}]
ParametricPlot3D[{Evaluate[r[t] /. s]*Cos[Evaluate[p[t] /. n]], 
  Evaluate[r[t] /. s]*Sin[Evaluate[p[t] /. n]], 
  Evaluate[r[t] /. s]*Cot[a]}, {t, 0, o}, PlotRange -> Full]
Plot[Evaluate[r[t] /. s]*Cos[Evaluate[p[t] /. n]], {t, 0, o}, 
 PlotRange -> All]
Plot[Evaluate[r[t] /. s]*Sin[Evaluate[p[t] /. n]], {t, 0, o}, 
 PlotRange -> All]
Plot[Evaluate[r[t] /. s]*Cot[a], {t, 0, o}, PlotRange -> All]
Plot[Evaluate[r[t] /. s], {t, 0, o}, PlotRange -> All]
Plot[Evaluate[p[t] /. n], {t, 0, o}, PlotRange -> All]

The code solves my DGL and plots the result. The last two plot function show the parameters r and p. The three lines above show the components from the parametric plot. The plots look like expected, but when combining them, the parametric plot is empty. Does anyone know why? Thank you very much!

POSTED BY: Emil Rosanowski

Emil,

you are already almost there! The only problem is that here NDSolve[] gives {{p -> InterpolatingFunction[...]}}, i.e. a list of a list of a rule. If you use such a construct as a replacement rule you get again a list:

a /. {{a -> b}}
(*  Out:  {b} *)

and so you end up with ParametricPlot3D[{{fx},{fy},{fz}}], but this does not work, you want instead ParametricPlot3D[{fx,fy,fz}]. So, what you can do is e.g. replacing NDSolve[...] with NDSolve[...][[1, 1]].

POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract