## Euler’s Method

### Learning Outcomes

• Use Euler’s Method to approximate the solution to a first-order differential equation

Consider the initial-value problem

${y}^{\prime }=2x - 3,y\left(0\right)=3$.

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 initial-value problem appears as the parabola in Figure 10.

The red graph consists of line segments that approximate the solution to the initial-value 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 right-hand 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 initial-value problem:

${y}^{\prime }={x}^{2}-{y}^{2},y\left(-1\right)=2$.

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(-1,2\right)$, the slope of the solution is given by $y^{\prime} ={\left(-1\right)}^{2}-{2}^{2}=-3$, so the slope of the tangent line to the solution at that point is also equal to $-3$. Now we define ${x}_{0}=-1$ and ${y}_{0}=2$. Since the slope of the solution at this point is equal to $-3$, we can use the method of linear approximation to approximate $y$ near $\left(-1,2\right)$.

$L\left(x\right)={y}_{0}+{f}^{\prime }\left({x}_{0}\right)\left(x-{x}_{0}\right)$.

Here ${x}_{0}=-1,{y}_{0}=2$, and ${f}^{\prime }\left({x}_{0}\right)=-3$, so the linear approximation becomes

$\begin{array}{cc}L\left(x\right)\hfill & =2 - 3\left(x-\left(-1\right)\right)\hfill \\ & =2 - 3x - 3\hfill \\ & =-3x - 1.\hfill \end{array}$

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:

${x}_{1}={x}_{0}+h=-1+0.1=-0.9$.

We can substitute ${x}_{1}=-0.9$ into the linear approximation to calculate ${y}_{1}$.

$\begin{array}{cc}{y}_{1}\hfill & =L\left({x}_{1}\right)\hfill \\ & =-3\left(-0.9\right)-1\hfill \\ & =1.7.\hfill \end{array}$

Therefore the approximate $y$ value for the solution when $x=-0.9$ is $y=1.7$. We can then repeat the process, using ${x}_{1}=-0.9$ and ${y}_{1}=1.7$ to calculate ${x}_{2}$ and ${y}_{2}$. The new slope is given by $y^{\prime} ={\left(-0.9\right)}^{2}-{\left(1.7\right)}^{2}=-2.08$. First, ${x}_{2}={x}_{1}+h=-0.9+0.1=-0.8$. Using linear approximation gives

$\begin{array}{cc}L\left(x\right)\hfill & ={y}_{1}+{f}^{\prime }\left({x}_{1}\right)\left(x-{x}_{1}\right)\hfill \\ & =1.7 - 2.08\left(x-\left(-0.9\right)\right)\hfill \\ & =1.7 - 2.08x - 1.872\hfill \\ & =-2.08x - 0.172.\hfill \end{array}$

Finally, we substitute ${x}_{2}=-0.8$ into the linear approximation to calculate ${y}_{2}$.

$\begin{array}{cc}{y}_{2}\hfill & =L\left({x}_{2}\right)\hfill \\ & =-2.08{x}_{2}-0.172\hfill \\ & =-2.08\left(-0.8\right)-0.172\hfill \\ & =1.492.\hfill \end{array}$

Therefore the approximate value of the solution to the differential equation is $y=1.492$ when $x=-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 the table below, rounded off to four decimal places.

 $n$ $0$ $1$ $2$ $3$ $4$ $5$ ${x}_{n}$ $-1$ $-0.9$ $-0.8$ $-0.7$ $-0.6$ $-0.5$ ${y}_{n}$ $2$ $1.7$ $1.492$ $1.3334$ $1.2046$ $1.0955$ $n$ $6$ $7$ $8$ $9$ $10$ ${x}_{n}$ $-0.4$ $-0.3$ $-0.2$ $-0.1$ $0$ ${y}_{n}$ $1.0004$ $1.9164$ $1.8414$ $1.7746$ $1.7156$

### Euler’s Method

Consider the initial-value problem

$y^{\prime} =f\left(x,y\right),y\left({x}_{0}\right)={y}_{0}$.

To approximate a solution to this problem using Euler’s method, define

$\begin{array}{c}{x}_{n}={x}_{0}+nh\hfill \\ {y}_{n}={y}_{n - 1}+hf\left({x}_{n - 1},{y}_{n - 1}\right).\hfill \end{array}$

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 11.

### Example: Using Euler’s Method

Consider the initial-value problem

${y}^{\prime }=3{x}^{2}-{y}^{2}+1,y\left(0\right)=2$.

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$.

Watch the following videos to see the worked solution to Example: Using Euler’s Method

For closed captioning, open the video on its original page by clicking the Youtube logo in the lower right-hand corner of the video display. In YouTube, the video will begin at the same starting point as this clip, but will continue playing until the very end.

### Key Takeaways

Consider the initial-value problem

${y}^{\prime }={x}^{3}+{y}^{2},y\left(1\right)=-2$.

Using a step size of $0.1$, generate a table with approximate values for the solution to the initial-value problem for values of $x$ between $1$ and $2$.