Before we start, just a simple example of a calculation in Mathematica. To execute the cell below, place the cursor in the cell and press ⇧+⌤.

2 + 2

How to plot a direction field in Mathematica?

A direction field is drawn using the PlotVectorField command. To use this command we  must first load a graphics package: (place the cursor in the cell below and press ⇧+⌤)

<< Graphics`PlotField`

Mathematica often complains about spelling errors. You can ignore those, or to awoid warnings about spelling errors execute the following command (place the cursor in the cell below and press ⇧+⌤):

Off[General::"spell1"];
Off[General::"spell"];

In the examples below you will need to change only the blue formulas to plot different direction fields.

Draw the direction field for the equation:   y' = y

We use  y  and  t  as variables. The first line in the cell below makes sure that  y  and  t  are not given any specific values.   The second line defines the slope as a function of  y  and t.  The formula for the slope is given by the differential equation.  The third line defines the window in which the direction field will be drawn.  You can change the blue numbers to get your picture right. Execute the cell below. (As above, place the cursor in the cell below and press ⇧+⌤.)

Clear[y, t];
slope=y;
tmin=-3; tmax=3; ymin=-3; ymax=3;

df=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},ScaleFactor->.4,ScaleFunction -> (1 &),AspectRatio -> 1, PlotPoints->25,ImageSize->300];

If you prefer the design from the book, then execute the following cell:

sf=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},HeadLength -> 0,ScaleFactor->.2,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];

Draw the direction field for the equation:   y' = t

Here we modify the blue parts in the previous example to get a direction field of  the given differential equation.

Clear[y, t]
slope=t;
tmin=-5; tmax=5; ymin=-5; ymax=5;

df=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},ScaleFactor->.6,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->25,ImageSize->300];

sf=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},HeadLength -> 0,ScaleFactor->.2,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];

Draw the direction field for the equation:   y' = (y^2) - t

Here we modify the blue parts in the previous example to get a direction field of  the given differential equation.

Clear[y, t]
slope=(y^2) - t;
tmin=-2; tmax=10; ymin=-4; ymax=4;

df=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},ScaleFactor->1/2,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->25,ImageSize->300];

sf=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},HeadLength -> 0,ScaleFactor->.3,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];

Draw the direction field for the equation:   y' = (y^2) + (t^2)-2

Here we modify the blue parts in the previous example to get a direction field of  the given differential equation.

Clear[y, t]
slope=y^2  +  t^2 - 2;
tmin=-3; tmax=3; ymin=-3; ymax=3;

df=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},ScaleFactor->.5,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->25,ImageSize->300];

sf=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},HeadLength -> 0,ScaleFactor->.2,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];

Draw the direction field for the equation:   y' = (Sqrt[y])

Again, we define the derivative as a function of  y and t.  This is given by the differential equation. Next we choose a window in which the direction field will be drawn.

Clear[y, t]
slope=(Sqrt[y]);
tmin=-3; tmax=3; ymin=0; ymax=3;

df=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},ScaleFactor->.4,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->25,ImageSize->300];

sf=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},HeadLength -> 0,ScaleFactor->.2,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];

Draw the direction field for the equation:   y' = 1/y

Again, we define the derivative as a function of  y and t.  This is given by the differential equation. Next we choose a window in which the direction field will be drawn.

Clear[y, t]
slope=1/y;
tmin=-3; tmax=3; ymin=-3; ymax=3;

df=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},ScaleFactor->.4,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];

sf=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},HeadLength -> 0,ScaleFactor->.2,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];

Try your equation here by modifying the blue expressin

Modify the blue parts in one of the previous example to get a direction field of  a differential equation of your choice.

Clear[y, t]
slope=y^2  +  t^2 - 2;
tmin=-3; tmax=3; ymin=-3; ymax=3;

df=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},ScaleFactor->.5,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->25,ImageSize->300];

sf=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},HeadLength -> 0,ScaleFactor->.2,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];

Draw the direction field for the equation:   y' = t/y

Again, we define the derivative as a function of  y and t.  This is given by the differential equation. Next we choose a window in which the direction field will be drawn.

Clear[y, t]
slope=t/y;
tmin=-3; tmax=3; ymin=-3; ymax=3;

df=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},ScaleFactor->.4,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];

sf=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},HeadLength -> 0,ScaleFactor->.2,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];

Draw the direction field for the equation:   y' = -t*y

Again, we define the derivative as a function of  y and t.  This is given by the differential equation. Next we choose a window in which the direction field will be drawn.

Clear[y, t]
slope=-t*y;
tmin=-3; tmax=3; ymin=-3; ymax=3;

df=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},ScaleFactor->.4,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];

sf=PlotVectorField[{1, slope},{t, tmin, tmax},{y, ymin, ymax}, Axes -> True,AxesLabel -> {t, y},HeadLength -> 0,ScaleFactor->.2,ScaleFunction -> (1 &),AspectRatio -> 1,PlotPoints->30,ImageSize->300];