0
$\begingroup$

So I am trying to Plot3D this first-order ODE:

$$ y'(x) = y$$

with the 3d coordinates (x,y,y'). I have read the documentation in Mathematica about 3DPlot and tried to "transfer" what I learned from there but it did not work. Any help would be really appreciated. Thanks!

$\endgroup$
3
  • 2
    $\begingroup$ Have you already seen ParametricPlot3D[]? $\endgroup$
    – J. M.'s torpor
    May 27 '20 at 15:14
  • $\begingroup$ I just read it now, and I tried several things but it still has not worked out for me yet even though I feel like I have an idea after reading it. $\endgroup$ May 27 '20 at 16:10
  • $\begingroup$ Clear["Global`*"]; sol[y0_] = DSolve[{y'[x] == y[x], y[0] == y0}, y, x][[1]]; ParametricPlot3D[{x, y[x], y'[x]} /. sol[1], {x, -3, 2}] $\endgroup$
    – Bob Hanlon
    May 27 '20 at 16:17
4
$\begingroup$

Try NDSolveValue and ParametricPlot3D:

ClearAll[ndsv]
ndsv[iv_?NumericQ] := NDSolveValue[{y'[x] == y[x], y[0] == iv}, {# &, y, y'}, {x, 0, 10}]

ParametricPlot3D[Evaluate[Table[Through@ndsv[iv]@t, {iv, 0, 3, .5}]], {t, 0, 10}, 
 BoxRatios -> 1, PlotLegends -> LineLegend[Range[0, 3, .5], LegendLabel -> "y[0]"]]

enter image description here

ParametricPlot3D[Through@ndsv[u]@t, {t, 0, 10}, {u, 0, 3}, 
 MeshFunctions -> {#5 &}, 
 Mesh -> {MapIndexed[{#, Directive[Thick, ColorData[97][#2[[1]]]]} &, Range[0, 3, .5]]},  
 BoxRatios -> 1, PlotStyle -> Opacity[.5, Blue], 
 Method -> "BoundaryOffset" -> False, Lighting -> "Neutral",
 PlotLegends -> LineLegend[97, Range[0, 3, .5], LegendLabel -> "y[0]"]]

enter image description here

$\endgroup$
4
  • $\begingroup$ Can we somehow "connect" all the line together so that the plot becomes like a smooth and continuous surface? $\endgroup$ May 27 '20 at 16:11
  • $\begingroup$ @TuanDucVu, please see the update. $\endgroup$
    – kglr
    May 27 '20 at 21:08
  • $\begingroup$ It seems like I have to learn quite a few more things in order to fully understand your code up there -- any suggestion would be appreciated --, but anyhow this is what I'm looking for. Thanks! $\endgroup$ May 27 '20 at 21:23
  • $\begingroup$ @TuanDucVu, my pleasure. Thank you for the accept. And welcome mma.se. $\endgroup$
    – kglr
    May 27 '20 at 21:29
3
$\begingroup$
Clear["Global`*"];
sol[y0_] = DSolve[{y'[x] == y[x], y[0] == y0}, y, x][[1]];

Show[
 ParametricPlot3D[
  {x, y[x], y'[x]} /. sol[y0],
  {x, -3, 2}, {y0, 0, 5},
  PlotStyle -> Opacity[0.8],
  Mesh -> None],
 ParametricPlot3D[Evaluate@
   Table[{x, y[x], y'[x]} /. sol[y0], {y0, 5, 0, -1}],
  {x, -3, 2},
  PlotLegends -> LineLegend[Automatic, Range[5, 0, -1],
    LegendLabel -> y[0]]],
 AxesLabel -> (Style[#, 14, Bold] & /@ {x, y[x], y'[x]}),
 BoxRatios -> {1, 1, 1}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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