1

I am reading "Dynamics and Bifurcations" by Hale and Kocac, and in chapter one the following diagram is shown:

direction field

Question is, how can I achieve the same plot using Mathematica? I've tried StreamPlot, but the plot I get looks somewhat different:

   StreamPlot[{-x, t}, {x, -3, 3}, {t, -3, 3}]

wrong stream plot?

What horrible mistake have I made? Sorry, but I'm fairly new to both ODEs and Mathematica. Thanks for the help.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Walter U.
  • 297
  • 1
  • 8

2 Answers2

2

I used the answer here and set the independent variable t as first argument. It looks now close to your book

f[t_, x_] := -x
StreamPlot[{1, f[t, x]}, {t, -2, 2}, {x, -.5, .5}, Frame -> False, 
 Axes -> True, AspectRatio -> 1/GoldenRatio]

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359
2
sol = DSolve[x'[t] == -x[t], x[t], t];
f = x[t] /. sol[[1]] /. C[1] -> x1;
p1 = ContourPlot[
   Evaluate[Table[x == f, {x1, {-.1, .1, 1, -1}}]], {t, -5, 
    5}, {x, -2, 2}];
points = Join @@ (Table[{i, j}, {i, -5, 5}, {j, -2, 2, .5}]);
line = Rotate[{Gray, Line[{# - {.3, 0}, # + {.3, 0}}]}, 
     ArcTan[-#[[2]]]] & /@ points;
p2 = Graphics[{line, {Red, PointSize[.01], Point[points]}}, 
   Axes -> True, PlotLabel -> "Direction Filed", Frame -> True, 
   PlotRange -> {-3, 3}];
Show[p2, p1]

enter image description here

Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78