6

Let's take this first example of a 2D output:

sol = DSolve[
        {y''[t] + y'[t] + y[t] == 3 Sin[t] - 4 Cos[t], 
         y[0] == a, y'[0] == 0},
         y[t], t
      ];
toplot = Table[ sol[[1, 1, 2]] /. a -> i, {i, 0, 3, 0.5}];
Plot[Tooltip[toplot], {t, 0, 2 \[Pi]}] 

How can I visualize these solutions with a 3-D output like the ones obtainable by ListSurfacePlot3D , the independant variable (a) of my example being the 3d coordinate? Here I would like to see 7 parallel curves.

Also another example this time for a system of two differential equations:

sol = DSolve[
        {x'[t] == x[t]/8 - y[t]  ,
         y'[t] == x[t]   + y[t]/8, 
         x[0] == 0,
         y[0] == 1},
         {x[t], y[t]}, t
      ];
ParametricPlot[{x[t], y[t]} /. sol, {t, -2 \[Pi], 2 \[Pi]}]

How can I get a 3D output of these solutions, the 3d coordinate being the variable t (and I expect to get a helix)? Thanks

Thies Heidecke
  • 8,814
  • 34
  • 44
Sigis K
  • 643
  • 4
  • 15

2 Answers2

11

Simplest solution I think would be just using ParametricPlot3D. For other techniques please see this questions:

Now let's look at specifically to your examples and ParametricPlot3D.

Your 1st example can be simplified a bit:

sol = DSolve[{y''[t] + y'[t] + y[t] == 3 Sin[t] - 4 Cos[t],y[0] == a,y'[0] == 0}, y[t], t];
toplot = Table[{t, sol[[1, 1, 2]], a}, {a, 0, 3, 0.5}];

ParametricPlot3D[toplot, {t, 0, 2 Pi}]

enter image description here

And 2nd example is fine as it is - just add time as 3rd variable to ParametricPlot3D:

ParametricPlot3D[{x[t], y[t], t} /. sol, {t, -2 Pi, 2 Pi}]

enter image description here

Vitaliy Kaurov
  • 73,078
  • 9
  • 204
  • 355
6

Also,

ClearAll[sol];
sol[a_?NumericQ] := sol[a] = DSolve[{y''[t] + y'[t] + y[t] == 3 Sin[t] - 4 Cos[t],
                                     y[0] == a, y'[0] == 0}, y[t], t];

Plot3D[Evaluate[y[t] /. sol[x]][[1]] /. t -> u, {u, 0, 2 Pi}, {x, 0, 10}]

Mathematica graphics

Please note that you have to Evaluate[] before injecting the (valued) variable u for the Solve[] function to work.

Edit

The above plot was done with:

Plot3D[Evaluate[y[t] /. sol[x]][[1]] /. t -> u, {u, 0, 2 Pi}, {x, 0, 5}, 
       MeshFunctions -> (#2 &), ColorFunction -> "BlueGreenYellow", 
       AxesLabel -> {Style[t, Large, Bold], Style[InputForm[y[0]], Large, Bold]}, 
       PlotStyle -> Directive[Opacity[.7], Specularity[.5]], BoxRatios -> 1]
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453