Euler's Method

We can use the idea behind slope fields to find approximate solutions to differential equations. In fact, when the computer generated solutions on the slope field in the last section, it was using a variation of Euler's Method to do so. Okay, so the question is: if we don't know exactly what the solution is, how can we still draw it? The key is that what we do know is the slope at any given point, and we know the starting point (we have to be given an initial condition in order to be able to do this).

Pretend that you're an investigator who's tracking a criminal. You know where he was last seen, and you have gotten inside his head to the point that you can predict at any point which way he would go if he were there. What would you do? Of course, you'd head to the criminal's last known location, and start heading the way that he would. Be careful, though; he might change direction, so if you just keep going straight forever, you'll get lost very quickly.

Okay, back up again to the criminal's last known location. Now start heading off in the direction that he would, but don't go very far. After a few steps, stop and reconsider, then head off in the direction he would go from this location. If you keep doing this process of going in the right direction, then stopping and recalibrating, you'll have a good chance of following at least close to the path of the criminal.

This illustrates the idea behind Euler's Method. We know where the solution begins and we know exactly what direction it would go at any point. We can put these two together to draw an approximate solution. The shorter our steps (meaning the more often we stop to recalibrate), the better our approximation will be, but that takes more computing power, so there's a tradeoff there. Essentially, though, we're approximating the solution with a series of short linear segments, as shown here.

The Algorithm

We're given two things: $y'=F(x,y)$ (the differential equation; we'll use $F$ instead of $y',$ but it's nothing different) and $y(x_0)=y_0$ (the initial condition). We'll also have a step size $h,$ which will either be given or we'll have to choose it. Our starting point, then is $(x_0,y_0),$ and all we need is a way to get from one point to the next. This is the algorithm.

Getting the next $x$ value is the easy part. This is just the previous $x$ value plus the step size: $x_1 = x_0 + h$

The tricky part, then, is finding the next $y$ value from the previous one; for this, we turn to the slope. Remember that slope is rise over run: \begin{aligned} F(x_0,y_0) &= \dfrac{y_1 - y_0}{x_1 - x_0} = \dfrac{y_1 - y_0}{h}\ hF(x_0,y_0) &= y_1 - y_0\ y_1 &= y_0 + hF(x_0,y_0) \end{aligned}

In general, we find each point using the previous point: \ans{\begin{aligned} x_n &= x_{n-1} + h\ y_n &= y_{n-1} + hF(x_{n-1}, y_{n-1}) \end{aligned}}

Examples

Use Euler's Method with a step size of $h=0.2$ to estimate $y(0.6)$ if $y' = x + y \textrm{ and } y(0) = 1.$

Solution

I like to build a table for these problems: $\begin{array}{c c c c} n & x_n & y_n & F(x_n, y_n)\ \hline 0 & 0 & 1 & \end{array}$

What we've inserted so far simply comes from the initial condition: when $n=0,$ $x_n=x_0=0$ and $y_n=y_0=1.$ Next, we can easily go down and add all the $x$ values that we need (up through $0.6$) just by adding $0.2$ each time we add a row: $\begin{array}{c c c c} n & x_n & y_n & F(x_n, y_n)\ \hline 0 & 0 & 1 & \ 1 & 0.2 & & \ 2 & 0.4 & & \ 3 & 0.6 & & \end{array}$

For the rest of the process, we bounce back and forth between $y_n$ and $F(x_n,y_n)$: first we find the first $F$ value, then use that to find the next $y$ value, which lets us find the next $F$ value, and so on. For instance, to find the first $F$ value, we note that $F(x,y)=x+y \longrightarrow F(x_0,y_0)=x_0+y_0=0+1=1.$

Then, to find the next $y$ value, we use the formula above: \begin{aligned} y_n &= y_{n-1} + hF(x_{n-1}, y_{n-1})\ y_1 &= y_0 + hF(x_0,y_0)\ &= 1 + (0.2)(1)\ &= 1.2 \end{aligned}

Repeating this process, we can fill in the rest of the table: $\begin{array}{c c c c} n & x_n & y_n & F(x_n, y_n)\ \hline 0 & 0 & 1 & 1 \ 1 & 0.2 & 1.2 & 1.4 \ 2 & 0.4 & 1.48 & 1.88 \ 3 & 0.6 & 1.856 & \end{array}$

Finally, we can estimate that when $x=0.6,$ $\ans{y \approx 1.856.}$

Notice that we didn't bother filling in any more in the table than we needed to; we stopped at $x=0.6,$ and we didn't bother filling in the last $F$ value.

1. Use Euler's Method with a step size of $h=0.1$ to estimate $y(1.5)$ if $y'=1-xy$ and $y(1)=1.$

2. $\begin{array}{c c c c} n & x_n & y_n & F(x_n, y_n)\ \hline 0 & 1 & 1 & 0 \ 1 & 1.1 & 1 & -0.1 \ 2 & 1.2 & 0.99 & -0.188 \ 3 & 1.3 & 0.9712 & -0.2626 \ 4 & 1.4 & 0.9449 & -0.3229 \ 5 & 1.5 & 0.9127 & \end{array}$

$\textrm{Therefore, } y(1.5) \approx 0.9127.$