Part III. First Order Ordinary Differential Equations
Section 3. Slope Fields:
A slope field (or direction field) for a first order ordinary differential equation of the form

y' = f( t, y )

is an array of short line segments. At point ( t, y) the segment has slope f( t, y ). Since these are tangent lines to the solution curves determined by the equation, a slope field can provide a wealth of information about the qualitative behavior of the solutions.  

The tool you need: PlotVectorField

The Mathematica procedure that creates vector fields is called PlotVectorField. A 2 dimensional vector field assigns a vector < u(x,y), v(x,y) > to each point ( x , y ) in the plane. Mathematica will plot these vectors with an entry of the form

PlotVectorField[ { u[x,y], v[x,y] }, {x,a,b}, {y,c,d} ]

This function must be loaded with a Graphics package called PlotField

In[1]:=

<<Graphics`PlotField`

Here, for example, is Mathematica's rendition of the vector field < -y , x > .

In[34]:=

PlotVectorField[ {-y,x}, {x,-3,3}, {y,-3,3}, Axes->True ]

[Graphics:HTMLFiles/Math_P3S3_1.gif]

Observe that 15 arrows are plotted horizontally and 15 vertically. This can be controlled by setting

PlotPoints -> n

which instructs PlotVectorField to plot n vectors in each direction (total = n^2). Here is the same vector field with 9 arrows in each direction.

In[37]:=

PlotVectorField[ {-y,x}, {x,-3,3}, {y,-3,3}, Axes->True, PlotPoints→9 ]

[Graphics:HTMLFiles/Math_P3S3_3.gif]

Each arrow is plotted with a length that is proportional to its true length. In the example above this makes for very short arrows near the origin. If the arrows are scaled to the same length, then the vector field is called a direction field.

In[40]:=

PlotVectorField[ {-y,x}/Sqrt[x^2+y^2], {x,-3,3}, {y,-3,3}, Axes->True,
                 PlotPoints→9, PlotLabel->"A direction field" ]

[Graphics:HTMLFiles/Math_P3S3_4.gif]

The slope field for y' = f( t, y )

The slope field for the first order differential equation y' = f ( t, y ) can be obtained by applying PlotVectorField to the vector field < 1 , f ( t, y ) > (normalized to unit length). The following entry produces the direction field for the differential equation

y' = y/(t^2 + 1)

In[174]:=

u = 1; v = y/(t^2+1);
PlotVectorField[ {u,v}/Sqrt[u^2+v^2], {t,-3,3}, {y,-3,3}, Axes->True,
                 PlotLabel->"A slope field" ]

[Graphics:HTMLFiles/Math_P3S3_6.gif]

We name the slope field S so we can show it with some solution curves below.

In[176]:=

S = %

Solution curves can be found using Table as follows.

In[170]:=

DE = y'[t] == y[t]/(t^2+1)
solns = Table[ DSolve[ {DE, y[0]==k}, y, t], {k,-3,3}];

Out[170]=

y^′[t] y[t]/(1 + t^2)

Using the solutions we use Table again to make the plots, then use Show to display them along with the slope field created above.

In[173]:=

Show[ S, Table[ Plot[ y[t]/.solns[[k]], {t,-3,3},
                PlotStyle->Thickness[0.01], DisplayFunction->Identity ],
                {k,7} ], PlotRange->{{-3,3},{-3,3}},
                DisplayFunction->$DisplayFunction,
                PlotLabel->"Slope field and solution curves"]

[Graphics:HTMLFiles/Math_P3S3_8.gif]

Compare this picture to the first one displayed in Section 1.

Keep your eye on  f ( t , y )

In general most points (t, y) in a direction field will have a locally unique solution curve passing through them.  "Locally unique" means the only solution through the point and lying within a small disc centered at ( t, y).  However, special attention must be  paid to "bad points" where either the function f or its y partial derivative is discontinuous. The equation named DE2 in  Section 1, and DE2 below, have lots of bad points (officially known as "singularities").  

In[157]:=

DE2 = y'[t] == y[t]/(t^2 - 1)
u = 1; v = y/(t^2 - 1);
S=PlotVectorField[ {u,v}/Sqrt[u^2+v^2], {t,-3,3}, {y,-3,3}, Axes->True ]

Out[157]=

y^′[t] y[t]/(-1 + t^2)

[Graphics:HTMLFiles/Math_P3S3_10.gif]

There are potential problems for any solution curve as it approaches the lines  t = 1 or t = -1. This is not  surprising because the function f is not defined at any point on either of these lines, all these points are singular  points for DE2:

f( t, y ) = y^2/(t^2 - 1)

The next picture displays the slope field and several solution curves.

The entries below are edited versions of the input used above to create the first picture of a slope field and solution curves.

In[160]:=

DE = y'[t] == y[t]/(t^2-1)
solns1 = Table[ DSolve[ {DE, y[0]==k}, y, t], {k,-3,3}];
solns2 = Table[ DSolve[ {DE, y[-2]==k}, y, t], {k,-3,3}];
solns3 = Table[ DSolve[ {DE, y[3]==k}, y, t], {k,-3,3}];
solns = Join[solns1,solns2,solns3];
Show[ S, Table[ Plot[ y[t]/.solns[[k]], {t,-3,3},
                PlotStyle->Thickness[0.01], DisplayFunction->Identity ],
                {k,21} ], PlotRange->{{-3,3},{-3,3}},
                DisplayFunction->$DisplayFunction,
                PlotLabel->"Slope field and solution curves"]

Out[160]=

y^′[t] y[t]/(-1 + t^2)

[Graphics:HTMLFiles/Math_P3S3_13.gif]

Finally, we make a slope field, solution curve picture for the last differential equation in Section 1.

In[112]:=

u = 1; v = t/y;
S=PlotVectorField[ {u,v}/Sqrt[u^2+v^2], {t,-3,3}, {y,-3,3}, Axes->True ]

[Graphics:HTMLFiles/Math_P3S3_14.gif]

Every point on the t axis is a singular point.

In[145]:=

DE3 = y'[t] == t/y[t]
solns1 = Table[ DSolve[ {DE3, y[k]==0.01}, y, t], {k,-3,3}];
solns2 = Table[ DSolve[ {DE3, y[k]==-0.01}, y, t], {k,-3,3}];
solns3 = Table[ DSolve[ {DE3, y[0]==k}, y, t], {k,-3.01,3.01}];
solns = Join[solns1,solns2,solns3];
Show[ S, Table[ Plot[ y[t]/.solns[[k]], {t,-3,3},
                PlotStyle->Thickness[0.01], DisplayFunction->Identity ],
                {k,21} ], PlotRange->{{-3,3},{-3,3}},
                DisplayFunction->$DisplayFunction,
                PlotLabel->"Slope field and solution curves"]

Out[145]=

y^′[t] t/y[t]

[Graphics:HTMLFiles/Math_P3S3_16.gif]

Go to Next Section Previous Section


Created by Mathematica  (September 13, 2004)