6
$\begingroup$

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

$\endgroup$
0

2 Answers 2

11
$\begingroup$

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

$\endgroup$
6
$\begingroup$

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]
$\endgroup$
5
  • $\begingroup$ The second solution gives an error message: $\endgroup$
    – Sigis K
    Aug 7, 2012 at 13:13
  • $\begingroup$ @SigismondKmiecik Works OK here. Try to run it on a fresh kernel, or insert a ClearAll before executing, because a previous definition of sol[] spoils it $\endgroup$ Aug 7, 2012 at 13:16
  • $\begingroup$ @SigismondKmiecik Answer updated with ClearAll $\endgroup$ Aug 7, 2012 at 13:22
  • $\begingroup$ It's ok after ClearAll["Global`*"]. Thanks $\endgroup$
    – Sigis K
    Aug 7, 2012 at 13:26
  • $\begingroup$ With your solution how you can you store in a table the equations of all the plotted solutions? Is it possible to use the Tooltip function in order to display the specific solutions on the output area? Thanks $\endgroup$
    – Sigis K
    Aug 12, 2012 at 14:16

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.