Learning Objectives
 4.2.1 Draw the direction field for a given firstorder differential equation.
 4.2.2 Use a direction field to draw a solution curve of a firstorder differential equation.
 4.2.3 Use Euler’s Method to approximate the solution to a firstorder differential equation.
For the rest of this chapter we will focus on various methods for solving differential equations and analyzing the behavior of the solutions. In some cases it is possible to predict properties of a solution to a differential equation without knowing the actual solution. We will also study numerical methods for solving differential equations, which can be programmed by using various computer languages or even by using a spreadsheet program, such as Microsoft Excel.
Creating Direction Fields
Direction fields (also called slope fields) are useful for investigating firstorder differential equations. In particular, we consider a firstorder differential equation of the form
An applied example of this type of differential equation appears in Newton’s law of cooling, which we will solve explicitly later in this chapter. First, though, let us create a direction field for the differential equation
Here $T\left(t\right)$ represents the temperature (in degrees Fahrenheit) of an object at time $t,$ and the ambient temperature is $72\text{\xb0}\text{F}\text{.}$ Figure 4.6 shows the direction field for this equation.
The idea behind a direction field is the fact that the derivative of a function evaluated at a given point is the slope of the tangent line to the graph of that function at the same point. Other examples of differential equations for which we can create a direction field include
To create a direction field, we start with the first equation: $y\prime =3x+2y4.$ We let $\left({x}_{0},{y}_{0}\right)$ be any ordered pair, and we substitute these numbers into the righthand side of the differential equation. For example, if we choose $x=1\phantom{\rule{0.2em}{0ex}}\text{and}\phantom{\rule{0.2em}{0ex}}y=2,$ substituting into the righthand side of the differential equation yields
This tells us that if a solution to the differential equation $y\prime =3x+2y4$ passes through the point $\left(1,2\right),$ then the slope of the solution at that point must equal $3.$ To start creating the direction field, we put a short line segment at the point $\left(1,2\right)$ having slope $3.$ We can do this for any point in the domain of the function $f\left(x,y\right)=3x+2y4,$ which consists of all ordered pairs $\left(x,y\right)$ in ${\mathbb{R}}^{2}.$ Therefore any point in the Cartesian plane has a slope associated with it, assuming that a solution to the differential equation passes through that point. The direction field for the differential equation ${y}^{\prime}=3x+2y4$ is shown in Figure 4.7.
We can generate a direction field of this type for any differential equation of the form $y\prime =f\left(x,y\right).$
Definition
A direction field (slope field) is a mathematical object used to graphically represent solutions to a firstorder differential equation. At each point in a direction field, a line segment appears whose slope is equal to the slope of a solution to the differential equation passing through that point.
Using Direction Fields
We can use a direction field to predict the behavior of solutions to a differential equation without knowing the actual solution. For example, the direction field in Figure 4.7 serves as a guide to the behavior of solutions to the differential equation $y\prime =3x+2y4.$
To use a direction field, we start by choosing any point in the field. The line segment at that point serves as a signpost telling us what direction to go from there. For example, if a solution to the differential equation passes through the point $\left(0,1\right),$ then the slope of the solution passing through that point is given by $y\prime =3\left(0\right)+2\left(1\right)4=\mathrm{2}.$ Now let $x$ increase slightly, say to $x=0.1.$ Using the method of linear approximations gives a formula for the approximate value of $y$ for $x=0.1.$ In particular,
Substituting $x=0.1$ into $L(x)$ gives an approximate $y$ value of $0.8.$
At this point the slope of the solution changes (again according to the differential equation). We can keep progressing, recalculating the slope of the solution as we take small steps to the right, and watching the behavior of the solution. Figure 4.8 shows a graph of the solution passing through the point $\left(0,1\right).$
The curve is the graph of the solution to the initialvalue problem
This curve is called a solution curve passing through the point $\left(0,1\right).$ The exact solution to this initialvalue problem is
and the graph of this solution is identical to the curve in Figure 4.8.
Checkpoint 4.7
Create a direction field for the differential equation $y\prime ={x}^{2}{y}^{2}$ and sketch a solution curve passing through the point $\left(\mathrm{1},2\right).$
Media
Go to this website to see more about slope fields.
Now consider the direction field for the differential equation $y\prime =(x3)({y}^{2}4),$ shown in Figure 4.9. This direction field has several interesting properties. First of all, at $y=\mathrm{2}$ and $y=2,$ horizontal dashes appear all the way across the graph. This means that if $y=\mathrm{2},$ then $y\prime =0.$ Substituting this expression into the righthand side of the differential equation gives
Therefore $y=\mathrm{2}$ is a solution to the differential equation. Similarly, $y=2$ is a solution to the differential equation. These are the only constantvalued solutions to the differential equation, as we can see from the following argument. Suppose $y=k$ is a constant solution to the differential equation. Then ${y}^{\prime}=0.$ Substituting this expression into the differential equation yields $0=\left(x3\right)\left({k}^{2}4\right).$ This equation must be true for all values of $x,$ so the second factor must equal zero. This result yields the equation ${k}^{2}4=0.$ The solutions to this equation are $k=\mathrm{2}$ and $k=2,$ which are the constant solutions already mentioned. These are called the equilibrium solutions to the differential equation.
Definition
Consider the differential equation $y\prime =f(x,y).$ An equilibrium solution is any solution to the differential equation of the form $y=c,$ where $c$ is a constant.
To determine the equilibrium solutions to the differential equation $y\prime =f(x,y),$ set the righthand side equal to zero. An equilibrium solution of the differential equation is any function of the form $y=k$ such that $f\left(x,k\right)=0$ for all values of $x$ in the domain of $f.$
An important characteristic of equilibrium solutions concerns whether or not they approach the line $y=k$ as an asymptote for large values of $x.$
Definition
Consider the differential equation ${y}^{\prime}=f\left(x,y\right),$ and assume that all solutions to this differential equation are defined for $x\ge {x}_{0}.$ Let $y=k$ be an equilibrium solution to the differential equation.
 $y=k$ is an asymptotically stable solution to the differential equation if there exists $\epsilon >0$ such that for any value $c\in \left(k\epsilon ,k+\epsilon \right)$ the solution to the initialvalue problem
$${y}^{\prime}=f\left(x,y\right),\phantom{\rule{1em}{0ex}}y\left({x}_{0}\right)=c$$
approaches $k$ as $x$ approaches infinity.  $y=k$ is an asymptotically unstable solution to the differential equation if there exists $\epsilon >0$ such that for any value $c\in \left(k\epsilon ,k+\epsilon \right)$ the solution to the initialvalue problem
$${y}^{\prime}=f\left(x,y\right),\phantom{\rule{1em}{0ex}}y\left({x}_{0}\right)=c$$
never approaches $k$ as $x$ approaches infinity.  $y=k$ is an asymptotically semistable solution to the differential equation if it is neither asymptotically stable nor asymptotically unstable.
Now we return to the differential equation $y\prime =(x3)({y}^{2}4),$ with the initial condition $y(0)=0.5.$ The direction field for this initialvalue problem, along with the corresponding solution, is shown in Figure 4.10.
The values of the solution to this initialvalue problem stay between $y=\mathrm{2}$ and $y=2,$ which are the equilibrium solutions to the differential equation. However, an initialvalue problem starting with $2<y<2$ can never cross the equilibrium solutions $y=2$ and $y=2$. Therefore, since ${y}^{2}4<0$ and for $x>3,y\text{'}=(x3)({y}^{2}4)<0$, $y$ is decreasing and therefore approaches $y=2$. Therefore, $y=2$ is an asymptotically stable solution to the differential equation.
What happens when the initial value is below $y=\mathrm{2}?$ This scenario is illustrated in Figure 4.11, with the initial value $y(0)=\mathrm{3}.$
We can see that for initial values $y<2$ for $x>3,y\text{'}(x3)({y}^{2}4)>0$ and $y$ is increasing and therefore approaches $y=2$. This reaffirms that $y=2$ is an asymptotically stable solution to the differential equation.
Example 4.8
Stability of an Equilibrium Solution
Create a direction field for the differential equation $y\prime ={(y3)}^{2}({y}^{2}+y2)$ and identify any equilibrium solutions. Classify each of the equilibrium solutions as stable, unstable, or semistable.
Solution
The direction field is shown in Figure 4.12.
The equilibrium solutions are $y=\mathrm{2},y=1,$ and $y=3.$ To classify each of the solutions, look at an arrow directly above or below each of these values. For example, at $y=\mathrm{2}$ the arrows directly below this solution point up, and the arrows directly above the solution point down. Therefore all initial conditions close to $y=\mathrm{2}$ approach $y=\mathrm{2},$ and the solution is stable. For the solution $y=1,$ all initial conditions above and below $y=1$ are repelled (pushed away) from $y=1,$ so this solution is unstable. The solution $y=3$ is semistable, because for initial conditions slightly greater than $3,$ the solution approaches infinity, and for initial conditions slightly less than $3,$ the solution approaches $y=3.$
Analysis
It is possible to find the equilibrium solutions to the differential equation by setting the righthand side equal to zero and solving for $y.$ This approach gives the same equilibrium solutions as those we saw in the direction field.
Checkpoint 4.8
Create a direction field for the differential equation $y\prime =(x+5)(y+2)({y}^{2}4y+4)$ and identify any equilibrium solutions. Classify each of the equilibrium solutions as stable, unstable, or semistable.
Euler’s Method
Consider the initialvalue problem
Integrating both sides of the differential equation gives $y={x}^{2}3x+C,$ and solving for $C$ yields the particular solution $y={x}^{2}3x+3.$ The solution for this initialvalue problem appears as the parabola in Figure 4.13.
The red graph consists of line segments that approximate the solution to the initialvalue problem. The graph starts at the same initial value of $\left(0,3\right).$ Then the slope of the solution at any point is determined by the righthand side of the differential equation, and the length of the line segment is determined by increasing the $x$ value by $0.5$ each time (the step size). This approach is the basis of Euler’s Method.
Before we state Euler’s Method as a theorem, let’s consider another initialvalue problem:
The idea behind direction fields can also be applied to this problem to study the behavior of its solution. For example, at the point $\left(\mathrm{1},2\right),$ the slope of the solution is given by $y\prime ={\left(\mathrm{1}\right)}^{2}{2}^{2}=\mathrm{3},$ so the slope of the tangent line to the solution at that point is also equal to $\mathrm{3}.$ Now we define ${x}_{0}=\mathrm{1}$ and ${y}_{0}=2.$ Since the slope of the solution at this point is equal to $\mathrm{3},$ we can use the method of linear approximation to approximate $y$ near $\left(\mathrm{1},2\right).$
Here ${x}_{0}=\mathrm{1},{y}_{0}=2,$ and ${f}^{\prime}\left({x}_{0}\right)=\mathrm{3},$ so the linear approximation becomes
Now we choose a step size. The step size is a small value, typically $0.1$ or less, that serves as an increment for $x;$ it is represented by the variable $h.$ In our example, let $h=0.1.$ Incrementing ${x}_{0}$ by $h$ gives our next $x$ value:
We can substitute ${x}_{1}=\mathrm{0.9}$ into the linear approximation to calculate ${y}_{1}.$
Therefore the approximate $y$ value for the solution when $x=\mathrm{0.9}$ is $y=1.7.$ We can then repeat the process, using ${x}_{1}=\mathrm{0.9}$ and ${y}_{1}=1.7$ to calculate ${x}_{2}$ and ${y}_{2}.$ The new slope is given by $y\prime ={\left(\mathrm{0.9}\right)}^{2}{\left(1.7\right)}^{2}=\mathrm{2.08}.$ First, ${x}_{2}={x}_{1}+h=\mathrm{0.9}+0.1=\mathrm{0.8}.$ Using linear approximation gives
Finally, we substitute ${x}_{2}=\mathrm{0.8}$ into the linear approximation to calculate ${y}_{2}.$
Therefore the approximate value of the solution to the differential equation is $y=1.492$ when $x=\mathrm{0.8}.$
What we have just shown is the idea behind Euler’s Method. Repeating these steps gives a list of values for the solution. These values are shown in Table 4.2, rounded off to four decimal places.
$n$  $0$  $1$  $2$  $3$  $4$  $5$ 
${x}_{n}$  $\mathrm{1}$  $\mathrm{0.9}$  $\mathrm{0.8}$  $\mathrm{0.7}$  $\mathrm{0.6}$  $\mathrm{0.5}$ 
${y}_{n}$  $2$  $1.7$  $1.492$  $1.3334$  $1.2046$  $1.0955$ 
$n$  $6$  $7$  $8$  $9$  $10$  
${x}_{n}$  $\mathrm{0.4}$  $\mathrm{0.3}$  $\mathrm{0.2}$  $\mathrm{0.1}$  $0$  
${y}_{n}$  $1.0004$  $1.9164$  $1.8414$  $1.7746$  $1.7156$ 
Theorem 4.1
Euler’s Method
Consider the initialvalue problem
$y\prime =f\left(x,y\right),\phantom{\rule{1em}{0ex}}y\left({x}_{0}\right)={y}_{0}.$
To approximate a solution to this problem using Euler’s method, define
Here $h>0$ represents the step size and $n$ is an integer, starting with $1.$ The number of steps taken is counted by the variable $n.$
Typically $h$ is a small value, say $0.1$ or $0.05.$ The smaller the value of $h,$ the more calculations are needed. The higher the value of $h,$ the fewer calculations are needed. However, the tradeoff results in a lower degree of accuracy for larger step size, as illustrated in Figure 4.14.
Example 4.9
Using Euler’s Method
Consider the initialvalue problem
Use Euler’s method with a step size of $0.1$ to generate a table of values for the solution for values of $x$ between $0$ and $1.$
Solution
We are given $h=0.1$ and $f\left(x,y\right)=3{x}^{2}{y}^{2}+1.$ Furthermore, the initial condition $y\left(0\right)=2$ gives ${x}_{0}=0$ and ${y}_{0}=2.$ Using Equation 4.2 with $n=0,$ we can generate Table 4.3.
$n$  ${x}_{n}$  ${y}_{n}={y}_{n1}+hf({x}_{n1},{y}_{n1})$ 
$0$  $0$  $2$ 
$1$  $0.1$  ${y}_{1}={y}_{0}+hf\left({x}_{0},{y}_{0}\right)=1.7$ 
$2$  $0.2$  ${y}_{2}={y}_{1}+hf\left({x}_{1},{y}_{1}\right)=1.514$ 
$3$  $0.3$  ${y}_{3}={y}_{2}+hf\left({x}_{2},{y}_{2}\right)=1.3968$ 
$4$  $0.4$  ${y}_{4}={y}_{3}+hf\left({x}_{3},{y}_{3}\right)=1.3287$ 
$5$  $0.5$  ${y}_{5}={y}_{4}+hf\left({x}_{4},{y}_{4}\right)=1.3001$ 
$6$  $0.6$  ${y}_{6}={y}_{5}+hf\left({x}_{5},{y}_{5}\right)=1.3061$ 
$7$  $0.7$  ${y}_{7}={y}_{6}+hf\left({x}_{6},{y}_{6}\right)=1.3435$ 
$8$  $0.8$  ${y}_{8}={y}_{7}+hf\left({x}_{7},{y}_{7}\right)=1.4100$ 
$9$  $0.9$  ${y}_{9}={y}_{8}+hf\left({x}_{8},{y}_{8}\right)=1.5032$ 
$10$  $1.0$  ${y}_{10}={y}_{9}+hf\left({x}_{9},{y}_{9}\right)=1.6202$ 
With ten calculations, we are able to approximate the values of the solution to the initialvalue problem for values of $x$ between $0$ and $1.$
Media
For more information on Euler's method use this applet.
Checkpoint 4.9
Consider the initialvalue problem
Using a step size of $0.1,$ generate a table with approximate values for the solution to the initialvalue problem for values of $x$ between $1$ and $2.$
Media
Visit this website for a practical application of the material in this section.
For the following problems, use the direction field below from the differential equation $y\prime =\mathrm{2}y.$ Sketch the graph of the solution for the given initial conditions.
$y\left(0\right)=1$
$y\left(0\right)=\mathrm{1}$
For the following problems, use the direction field below from the differential equation $y\prime ={y}^{2}2y.$ Sketch the graph of the solution for the given initial conditions.
$y\left(0\right)=3$
$y\left(0\right)=\mathrm{1}$
Draw the direction field for the following differential equations, then solve the differential equation.
$y\prime ={t}^{3}$
$\frac{dy}{dx}={x}^{2}\text{cos}\phantom{\rule{0.1em}{0ex}}x$
$\frac{dx}{dt}=\text{cosh}\left(t\right)$
Draw the directional field for the following differential equations. What can you say about the behavior of the solution? Are there equilibria? What stability do these equilibria have?
$y\prime =yx$
$y\prime ={t}^{2}\text{sin}\phantom{\rule{0.1em}{0ex}}y$
Match the direction field with the given differential equations. Explain your selections.
$y\prime =\mathrm{3}y$
$y\prime ={e}^{t}$
$y\prime =\text{\u2212}ty$
Match the direction field with the given differential equations. Explain your selections.
$y\prime =\text{\u2212}t\phantom{\rule{0.1em}{0ex}}\text{cos}\phantom{\rule{0.1em}{0ex}}y$
$y\prime ={\text{sin}}^{2}y$
Estimate the following solutions using Euler’s method with $n=5$ steps over the interval $t=[0,1].$ If you are able to solve the initialvalue problem exactly, compare your solution with the exact solution. If you are unable to solve the initialvalue problem, the exact solution will be provided for you to compare with Euler’s method. How accurate is Euler’s method?
$y\prime =\mathrm{3}y,\phantom{\rule{1em}{0ex}}y\left(0\right)=1$
${y}^{\prime}=3ty,y(0)=1.$ Exact solution is $y=3t+4{e}^{\text{\u2212}t}3$
${y}^{\prime}=2t,y(0)=0$
[T] $y\prime ={e}^{(x+y)},y(0)=\mathrm{1}.$ Exact solution is $y=\text{\u2212}\text{ln}(e+1{e}^{x})$
${y}^{\prime}={y}^{2}\text{ln}(x+1),y(0)=1.$ Exact solution is $y=\frac{1}{(x+1)(\text{ln}(x+1)1)}$
${y}^{\prime}=y,y(0)=\mathrm{1}.$ Exact solution is $y=\text{\u2212}{e}^{x}.$
Differential equations can be used to model disease epidemics. In the next set of problems, we examine the change of size of two subpopulations of people living in a city: individuals who are infected and individuals who are susceptible to infection. $S$ represents the size of the susceptible population, and $I$ represents the size of the infected population. We assume that if a susceptible person interacts with an infected person, there is a probability $c$ that the susceptible person will become infected. Each infected person recovers from the infection at a rate $r$ and becomes susceptible again. We consider the case of influenza, where we assume that no one dies from the disease, so we assume that the total population size of the two subpopulations is a constant number, $N.$ The differential equations that model these population sizes are
Here $c$ represents the contact rate and $r$ is the recovery rate.
Show that, by our assumption that the total population size is constant $(S+I=N),$ you can reduce the system to a single differential equation in $I\text{:}\phantom{\rule{0.2em}{0ex}}I\prime =c(NI)IrI.$
[T] Use computational software or a calculator to compute an approximate solution to the initialvalue problem $y\prime =ty,\phantom{\rule{1em}{0ex}}y\left(0\right)=2$ using Euler's Method with a given step size $h.$ Find the solution at $t=1$ in terms of $h.$ Hint: Here is "pseudocode" for how to write a computer program to perform Euler's Method for $y\prime =f(t,y),y(0)={y}_{0}\text{:}$

Create function $f(t,y).$

Define parameters $y\left(0\right)={y}_{0},\phantom{\rule{0.5em}{0ex}}t\left(0\right)=0,$ step size $h,$ and total number of steps, $N$

Write a for loop:
for $\text{k}=0\phantom{\rule{0.2em}{0ex}}\mathbf{\text{to}}\phantom{\rule{0.2em}{0ex}}N$
$\phantom{\rule{2em}{0ex}}\text{fn}=\text{f}\left(\text{t}\left(\text{k}\right),\text{y}\left(\text{k}\right)\right)$
$\phantom{\rule{2em}{0ex}}\text{y}\left(\text{k+1}\right)=\text{y}\left(\text{k}\right)+\text{h*fn}$
$\phantom{\rule{2em}{0ex}}\text{t}\left(\text{k+1}\right)=\text{t}\left(\text{k}\right)+\text{h}$
Refer to your answer for Exercise 4.106 to solve the following exercises.
Draw the directional field
Compute using [T] $h=0.1$
Compute using [T] $h=0.0001$
[T] Evaluate the exact solution at $t=1.$ Make a table of errors for the relative error between the Euler’s method solution and the exact solution. How much does the error change? Can you explain?
Consider the initialvalue problem $y\prime =\mathrm{2}y,\phantom{\rule{1em}{0ex}}y(0)=2.$
Show that $y=2{e}^{\mathrm{2}x}$ solves this initialvalue problem.
[T] By hand or by calculator or computer, approximate the solution using Euler’s Method at $t=10$ using $h=5.$
[T] By calculator or computer, approximate the solution using Euler’s Method at $t=10$ using $h=100.$
[T] Plot exact answer and each Euler approximation (for $h=5$ and $h=100)$ at each $h$ on the directional field. What do you notice?