Message Boards Message Boards

Plot a system of differential parametric equations with ParametricNDSolve?

Posted 5 years ago

Hey all,

I'm pretty new to Mathematica so go easy on me. I have been trying to plot a system of differential parametric equations without any success. It appears as though Mathematica is solving them, but it won't plot them. I have put my code that I am using below and was hoping someone could take a look at what I did wrong:

a = .1
ParametricPlot3D[{Sin[t], Cos[t], t/4}, {t, 0, 2 Pi}]

 sol = ParametricNDSolve[{x'[t] == t,  y'[t] == t^2, z'[t] == 3*t, 
   x[0] == 1, y[0] == 0, z[0] == 0}, {x, y, z}, {t, 0, 100} , {}]
ParametricPlot3D[sol, {t, 0, 100 }, PlotRange -> All]
 sol2 = ParametricNDSolve[{x'[
     t] == ( -Sin[t]*(1 + a^2 + t^2) - 
       2*t*Cos (t))/(1 + a^2 + t^2)^2,  
   y'[t] == ( 
      Cos[t]*(1 + a^2 + t^2) - 2*t*Sin (t))/(1 + a^2 + t^2)^2, 
   z'[t] == a*(1 + a^2 - t^2)/(1 + a^2 + t^2)^2, x[0] == 1, 
   y[0] == 0, z[0] == 0}, {x, y, z}, {t, 0, 100} , {}]
ParametricPlot3D[sol2, {t, 0, 100 }, PlotRange -> All]
POSTED BY: Michael Solomon
2 Replies

not sure how the solution looks like but this plots something

ParametricPlot3D[
 Evaluate[{x[][t], y[][t], z[][t]} /. sol2], {t, 0, 100}, 
 PlotRange -> All, BoxRatios -> {1, 1, 1}]

Never used ParametricNDSolve solve but what i can see it that it generates a list of replacement rules with ParametericFunction objects.

enter image description here

so x /. sol replaces x with the function. Such a function takes a parameter value, in this case this is empty so x[] generates a interpalotion function that takes the parameter t

{x[][t], y[][t], z[][t]} /. sol2

generates enter image description here

Since Plot functions have the HoldAll attribute you have to put this into the Evaluate[] for it to actually plot.

you also had some typos in your equation Sin[t] and Cos[t].

sol2 = ParametricNDSolve[{x'[
     t] == (-Sin[t]*(1 + a^2 + t^2) - 2*t*Cos[t])/(1 + a^2 + t^2)^2, 
   y'[t] == (Cos[t]*(1 + a^2 + t^2) - 2*t*Sin[t])/(1 + a^2 + t^2)^2, 
   z'[t] == a*(1 + a^2 - t^2)/(1 + a^2 + t^2)^2, x[0] == 1, y[0] == 0,
    z[0] == 0}, {x, y, z}, {t, 0, 100}, {a}]
ParametricPlot3D[
 Evaluate[{x[.1][t], y[.1][t], z[.1][t]} /. sol2], {t, 1, 100}, 
 PlotRange -> All, BoxRatios -> {1, 1, 1}]

enter image description here

POSTED BY: Martijn Froeling

Try,using NDSolve:

 ClearAll["Global`*"]; Remove["Global`*"];

 sol = NDSolve[{x'[t] == t, y'[t] == t^2, z'[t] == 3*t, x[0] == 1, 
     y[0] == 0, z[0] == 0}, {x, y, z}, {t, 0, 10}];
 ParametricPlot3D[{x[t], y[t], z[t]} /. sol, {t, 0, 10}, 
  PlotRange -> All, AspectRatio -> 1/2, 
  AxesLabel -> {"x[t]", "y[t]", "z[t]"}]

 a = 1/10; 
  sol2 = NDSolve[{x'[
      t] == (-Sin[t]*(1 + a^2 + t^2) - 2*t*Cos[t])/(1 + a^2 + t^2)^2, 
    y'[t] == (Cos[t]*(1 + a^2 + t^2) - 2*t*Sin[t])/(1 + a^2 + t^2)^2, 
    z'[t] == a*(1 + a^2 - t^2)/(1 + a^2 + t^2)^2, x[0] == 1, y[0] == 0,
     z[0] == 0}, {x, y, z}, {t, 0, 10}];
ParametricPlot3D[{x[t], y[t], z[t]} /. sol2, {t, 0, 10}, 
 PlotRange -> All, AspectRatio -> 1, 
 AxesLabel -> {"x[t]", "y[t]", "z[t]"}]

Or using ParametricNDSolve:

  ClearAll["Global`*"]; Remove["Global`*"];

  sol3 = ParametricNDSolve[{x'[
        t] == (-Sin[t]*(1 + a^2 + t^2) - 2*t*Cos[t])/(1 + a^2 + t^2)^2, 
      y'[t] == (Cos[t]*(1 + a^2 + t^2) - 2*t*Sin[t])/(1 + a^2 + t^2)^2, 
      z'[t] == a*(1 + a^2 - t^2)/(1 + a^2 + t^2)^2, x[0] == 1, 
      y[0] == 0, z[0] == 0}, {x, y, z}, {t, 0, 10}, {a}];
ParametricPlot3D[{x[a][t], y[a][t], z[a][t]} /. sol3 /. a -> 1/10, {t,0, 10}, PlotRange -> All, AspectRatio -> 1, AxesLabel -> {"x[t]", "y[t]", "z[t]"}]
POSTED BY: Mariusz Iwaniuk
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