Limited and Unlimited Growth
The HIV Epidemic in Vancouver's Lower East Side
UBC Calculus Online Course Notes

Euler's Method

We have seen how to use a direction field to obtain qualitative information about the solutions to a differential equation. This simple kind of reasoning lead to predictions for the eventual behaviour of solutions to the logistic equation.

Sometimes, however, we want more detailed information. For instance, we might want to know how long it will take before the solution is near the limiting value. In this case, we can use the linear approximation to numerically approximate solutions to differential equations. We will demonstrate this approach through an example.



A Simple Initial Value Problem

Let's start by looking at an initial value problem whose solution is known:


\begin{eqnarray*} 
\frac{dy}{dt} & = & y \\ 
y(0) & = & 1 
\end{eqnarray*}

We know that the solution is $  y(t) = e^t  $ . This means that after we find our approximate solution, we will be able to determine how good of an approximation it really is.

Let's suppose that we are interested in the value of the solution at $  t = 1  $ . We know the value at $  t = 0 $ since that is a part of the initial value problem---namely, $  y(0) = 1 
 $ . Notice that the differential equation also tells us the derivative of the solution at $  t = 0 $ since

\[  \frac{dy}{dt}(0) = y(0) = 1 
 \]

If we now form the linear approximation at $  t = 0  $ , we find that $  l(t) = 1 + 1(t - 0) = 1+t  $ . Then our approximation yields

\[  y(1) = e = 2.71828 \approx l(1) = 1+1 = 2. 
 \]

This approximation is not too good but it was easy to obtain. Graphically, the picture is like this:

The problem with the approximation is that the derivative of the solution is changing across the interval $  [0,1]  $ but the approximation assumes that it is constantly 1 . We can try to fix this up by diving the interval into two pieces: First, we will use the linear approximation based at $  t = 0  $ to approximate the value at $  t = \frac 12  $ . Then we will use a linear approximation at $  t = \frac 12  $ to obtain an approximate value at $  t = 1 $ .

We have already obtained the linear approximation $  l(t) = 1+t 
 $ based at $  t = 0  $ . This produces the approximate value $  y(\frac 12) \approx l(\frac 12) = \frac 32  $ . This tells us that the solution curve approximately passes through $ 
(\frac 12, \frac 32)  $ . That means that

\[  \frac{dy}{dt}(\frac 12) = y(\frac 12) \approx \frac 32. 
 \]

We will then form the linear approximation at the point $ 
(\frac 12, \frac 32)  $ : it produces

\[ 
l(t) = \frac 32 + \frac 32(t - \frac 12) 
 \]

which yields the approximation $  y(1) \approx l(1) = \frac 94 
= 2.25 
 $ . This is, in fact, a better approximation to the value $ 
y(1) = e = 2.71828... $ . Graphically, what we have done is illustrated in the diagram.

Here you can see why we have a better approximation: the derivative of the solution changes as we move across the interval $  [0,1]  $ . In the second approximation, we take this into account by stopping at $  t = \frac 12  $ , recomputing the derivative and then continuing on.

Now you can probably imagine that we will get better approximations if we take shorter steps and correct the slope at every step. To do this, imagine walking from 0 to 1 by taking n steps, each of width $  \frac 1n  $ . We will call the points we obtain $ 
(t_j, y_j) $ .

Notice that $ 
(t_0, y_0) = (0,1)  $ since this is where the initial value problem tells us to begin. To get from one step to the next, we are assuming that the solution approximately passes through $  (t_j, 
y_j)  $ . At that point, the derivative, which is equal to the y coordinate by the differential equation, is $ 
y_j  $ . That means that the linear approximation at that point is

\[  l(t) = y_j + y_j(t - t_j) 
 \]

This means that at $  t = t_j  $ , we have

 
\begin{eqnarray*} 
y(t_{j+1}) & \approx & y_{j+1} = l(t_{j+1}) = y_j + y_j(t_{j+1} - t_j) 
\\ 
y_{j+1} & = & y_j + y_j \frac 1n 
\end{eqnarray*}
The following demonstration will let you select the number of steps and show you the approximate solution (type in the number of steps and press "Return"). Notice that as the number of steps gets larger, the approximation becomes very good.



Euler's Method

Now we will work with a general initial value problem

\begin{eqnarray*} 
\frac{dy}{dt} & = & f(y) \\ 
y(0) & = & y_0 
\end{eqnarray*}

We will again form an approximate solution by taking lots of little steps. We will call the distance between the steps h and the various points $  (t_j, y_j)  $ . To get from one step to the next, we will form the linear approximation at $ 
t_j $ . The derivative at this point is given by the differential equation: $  \frac{dy}{dt} = f(y)  $ . The linear approximation is then

\[  l(t) = y_j + f(y_j) (t-t_j) 
 \]

so that

\[ y_{j+1} = l(t_{j+1}) = y_j + f(j_j) h. 
 \]

This technique is called Euler's Method.



The logistic equation

Now we will consider the initial value problem


\begin{eqnarray*} 
\frac{dy}{dt} & = & y - \frac 12 y^2 \\ 
y(0) & = & 1 
\end{eqnarray*}

Notice that this has the basic form of the logistic equation. We have studied this equation qualitatively, but we do not explicitly know solutions. As an example, we will approximate the solution on the interval $  [0.6] $ by taking steps of width h.

Applying Euler's Method, we can generate an approximate solution by

 \begin{eqnarray*} 
y_0 & = & 1 \\ 
y_{j+1} & = & y_j + (y_j - \frac 12 y_j^2)h 
\end{eqnarray*}
In the demonstration below, you can enter the number of steps and see the approximate solution. Again, as you take more steps, the solution does not vary too much when you increase the number of steps. You can then feel confident that your solution is a good approximation.