Mathematica 1: Slope fields and stream lines

Mathematica 1: Slope fields and stream lines
Example: Use Mathematica to draw the slope field of the following differential
equation:
dy
= −y 2 + 2 cos(x).
dx
We first input the following command and press Shift+Enter to get a figure
of vector fields 1.
VectorPlot[{1, -yˆ2+2Cos[x]},{x,-3,3}, {y,-3,3}]
Pay attention to the following input rules of commands: (a): the upper
cases, and (b): the type of brackets.
Figure 1: Vector field
1
The vectors were scaled according to their lengths, to uniformize the lengths
and remove the arrow heads, we can input:
VectorPlot[{1, -yˆ2+2Cos[x]},{x,-3,3}, {y,-3,3},
VectorScale -> {Tiny, Automatic, None}, VectorStyle ->Arrowheads[0]]
Press Shift+Enter to get figure 2 (slope fields):
Figure 2: Slope field
2
To get specific stream lines, just add the stream points. Here we add three
stream points: (−2, −2), (−2, −0.5), (−2, 0):
VectorPlot[{1, -yˆ2+2Cos[x]},{x,-3,3}, {y,-3,3},
VectorScale->{Tiny, Automatic, None}, VectorStyle->Arrowheads[0],
StreamPoints-> {{-2,-2},{-2,-0.5},{-2,0}}]
Figure 3: Slope field with stream lines
Note that we have added the optional property StreamStyle to specify the
thickness of streamlines.
3
We could also plot lots of stream lines using the commands:
StreamPlot[{1, -yˆ2+2Cos[x]},{x,-3,3}, {y,-3,3}]
Figure 4: Stream field
4