I am relatively very new to mathematica, but I have been trying to figure this out for hours. I have a second-order differential equation, $$ ay''+by'+cy=0 $$ and I have converted it into a first-order system, but I have no clue how to plot the phase portrait. I don't really know how to code in mathematica and all the "tutorials" are very complicated so if someone could help me out, that would be amazing! thank you

  • $\begingroup$ That gives me the direction field/slope field but not a true phase portrait. Is there any way to plot the phase portrait? I saw some examples that were able to, but they were VERY complicated $\endgroup$
    – user71607
    Commented Apr 1, 2020 at 5:49
  • $\begingroup$ here is mathematica.stackexchange.com/q/14160 an example I found, but I cannot follow because it's so complicated and old. A phase portrait has many possible solution curves $\endgroup$
    – user71607
    Commented Apr 1, 2020 at 6:00
  • $\begingroup$ Okay, I see, I just didn't know how to plot multiple lines on one plot if that makes sense. Is there anyway for mathematica to find the different "solutions" or do I have to find them myself then plot them? $\endgroup$
    – user71607
    Commented Apr 1, 2020 at 6:05
  • $\begingroup$ hi Tamecarlos23, you modified your question and the equation and now the answer below do not reflect the ode in the question. It would be better to ask new question if you need to keep the answers valid to the original question. $\endgroup$
    – Nasser
    Commented Apr 1, 2020 at 23:24

2 Answers 2


Another alternative to make Phase plot is by using StreamPlot and there is really no need to solve the ode.

You can tell StreamPlot to color specific solution trajectories by indicating a point on the curve (normally the initial conditions). It will then color that specific solution curve with that color.

f1 = v;
f2 = -5 v - 3 u + u^2;
StreamPlot[{f1, f2}, {u, 0, 2.5}, {v, -2, 6}, Axes -> True, 
 AxesLabel -> {"v", "u"}, BaseStyle -> 12,
 StreamPoints -> {{{{1, 0}, Red}, {{1, 1}, Blue}, {{1, 2}, 
     Cyan}, {{1, 3}, Green}, Automatic}}, Frame -> False

Mathematica graphics

help has many option to customize the above.


This equation can't be done analytically (MMA version 8.0). Do it with NDSolve. You do not need generate a first order system. (I did it with NDSolve; in higher versions you can use more elegant NDSolveValue).

xsol[x0_, xs0_] := 
   x /. First@
NDSolve[{x''[t] + 5 x'[t] + 3 x[t] - x[t]^2 == 0, x[0] == x0, 
 x'[0] == xs0}, x, {t, 0, 10}]

Plot[Evaluate[{xsol[1, 0][t], xsol[1, 0]'[t]}], {t, 0, 10}, 
PlotStyle -> {Blue, Red}, PlotRange -> All]

  Evaluate[Table[{xsol[1, j][t], xsol[1, j]'[t]}, {j, 0, 5, 1}]], {t, 0, 10}, 
PlotStyle -> {Black, Red, Green, Blue, Cyan, Magenta}]

Edit corrected typing error

enter image description here

  • $\begingroup$ This is great, thank you! But what is the difference between this code and code in the version 12 of mathematica? I am desperately trying to make this work and it won't run for my version $\endgroup$
    – user71607
    Commented Apr 1, 2020 at 6:21
  • $\begingroup$ I don't have version 12. My be you get examples in the manual. $\endgroup$
    – Akku14
    Commented Apr 1, 2020 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.