# Euler's Method

**Euler's method** is used for approximating solutions to certain differential equations and works by approximating a solution curve with line segments. In the image to the right, the blue circle is being approximated by the red line segments.

In some cases, it's not possible to write down an equation for a curve, but we can still find approximate coordinates for points along the curve by using simple lines. These line segments have the same slope as the curve, so they stay relatively close to it.

Euler's method is useful because differential equations appear frequently in physics, chemistry, and economics, but usually cannot be solved explicitly, requiring their solutions to be approximated. For example, Euler's method can be used to approximate the path of an object falling through a viscous fluid, the rate of a reaction over time, the flow of traffic on a busy road, to name a few.

#### Contents

## Intuition

While Euler's method can seem complicated, the idea behind it is very simple.

Suppose we have a function \(f(x)\), and we know the value of \(f\) at a point \(x_0\), and \(f'(x_0)\). If we want to find the value of \(f\) at a point close to \(x\), say \(x+h\), then we can approximate \(f(x+h)\) by using the tangent line to the graph at the point \((x_0,f(x_0))\), as shown in the image to the right. The idea is that \(f'(x_0)\) estimates how much change there is in \(y\) for each change in \(x\); we know that \(x\) increased by \(h\), so \(y\) should have increased by approximately \(h f'(x_0)\), so the new value should be \(f(x_0)+hf'(x_0)\).

Of course, as \(h\) gets larger, our approximation becomes less and less accurate. The idea behind Euler's method is to remedy this by repeatedly using tangent line approximations, so for example, to approximate \(f(x+3h)\) by first approximating \(f(x+h)\), then \(f(x+2h)\), and then \(f(x+3h)\). At each step, we use the slope of the curve to construct the next line segment, and this allows us to "follow" the curve with line segments, as shown in the image to the right. This number \(h\) is called the step size, and measures how small the approximating segments are.

## The Method

For a differential equation of the form \(y'=f(x)\) where \(y(x_0)=y_0\), a sequence of points \(x_n, y_n\) satisfying \(x_{n+1}=x_n+h\quad\text{and}\quad y_{n+1}=y_n+hf(x_n)\), where \(h\) is the step size, can be used to approximate \(y(x)\) for some \(x\). The idea is to choose \(h\), the step size, so that one of the \(x_n\) will be the \(y\)-value to be estimated. For example, if \(x_0=1\) and the goal is to estimate the value at 5, one must choose \(h=1\) so \(x_5=x_0+4h=5\).

Consider a function \(f(x)\) such that \(f(2)=10\) and \(f'(x)=x^{2}+3x\) . Using Euler's method with step size \(1,\) find the resulting approximation of \(f(5).\)

We have \((x_0,y_0)=(2,10)\). Using Euler's method with step size \(h=1,\) we compute \[\begin{align} (x_1,y_1)&=(2+1,10+1\cdot f'(2))=(3,20),\\ (x_2,y_2)&=(3+1,20+1\cdot f'(3))=(4,38),\\ (x_3,y_3)&=(4+1,38+1\cdot f'(4))=(5,78), \end{align}\] and so \(f(5)\approx 78\).

This method can also be used for first order differential equations, which are equations of the form \(\frac{dy}{dx}=f(x,y)\). In this case, the slope of the tangent line is an expression involving both \(x \text{ and } y\), so we use the recurrences \(x_{n+1}=x_n+h\quad\text{and}\quad y_{n+1}=y_n+hf(x_n,y_n),\) but the idea is essentially the same.

Consider a function \(y(x)\) such that \(y(0)=1\) and \(\frac{dy}{dx}=3x+y\) . Using Euler's method with step size \(1,\) find the resulting approximation of \(y(3).\)

We have \((x_0,y_0)=(0,1)\). Using Euler's method with step size \(h=1,\) we compute \[\begin{align} (x_1,y_1)&=(0+1,1+1\cdot (3\cdot 0+1))=(1,2),\\ (x_2,y_2)&=(1+1,2+1\cdot (3\cdot 1+2))=(2,7),\\ (x_3,y_3)&=(2+1,7+1\cdot (3\cdot 2+7))=(3,20), \end{align}\] and so \(y(3)\approx 20\).

For which of the following differential equations will Euler's method always produce an overestimate of the true value?

## Effects of Step Size

As \(h\) becomes smaller, the approximations become better and better, because smaller lines stay closer to the graph.

Consider a very simple example, a function \(f(x)\) for which \(f'(x)=f(x)\) and \(f(0)=1\). This differential equation can be solved exactly, and has solution \(f(x)=e^x\), so we know that the exact value of \(f(1)\) is \(e\approx 2.718\). Use Euler's method to approximate \(f(1)\) with step size \(h=0.5\) and then with \(h=0.2\), and compare the two approximations.

We have \((x_0,y_0)=(0,1)\). Using Euler's method with step size \(h=0.5,\) we compute \[\begin{align} (x_1,y_1)&=(0+0.5,1+0.5\cdot 1)=(0.5,1.5),\\ (x_2,y_2)&=(0.5+0.5,1.5+0.5\cdot 1.5)=(1,2.25),\\ \end{align}\] and so \(f(1)\approx 2.25\). On the other hand, using Euler's method with step size \(h=0.2\), we find

\[\begin{align} (x_1,y_1)&=(0+0.2,1+0.2\cdot 1)=(0.2,1.2),\\ (x_3,y_2)&=(0.2+0.2,1.2+0.2\cdot 1.2)=(0.4,1.44),\\ (x_4,y_2)&=(0.4+0.2,1.44+0.2\cdot 1.44)=(0.6,1.728),\\ (x_5,y_2)&=(0.6+0.2,1.728+0.2\cdot 1.728)=(0.8,2.0736),\\ (x_2,y_2)&=(0.8+0.2,2.0736+0.2\cdot 2.0736)=(1,2.4883),\\ \end{align}\] giving \(f(1)\approx 2.4883\), a better estimate. A visual comparison of the two estimates is shown at right.