# 7.3: Euler's Method

- Page ID
- 107840

\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

\( \newcommand{\Span}{\mathrm{span}}\)

\( \newcommand{\id}{\mathrm{id}}\)

\( \newcommand{\Span}{\mathrm{span}}\)

\( \newcommand{\kernel}{\mathrm{null}\,}\)

\( \newcommand{\range}{\mathrm{range}\,}\)

\( \newcommand{\RealPart}{\mathrm{Re}}\)

\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

\( \newcommand{\Argument}{\mathrm{Arg}}\)

\( \newcommand{\norm}[1]{\| #1 \|}\)

\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)

\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)

\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

\( \newcommand{\vectorC}[1]{\textbf{#1}} \)

\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)- What is Euler's method and how can we use it to approximate the solution to an initial value problem?
- How accurate is Euler's method?

In Section 7.2, we saw how a slope field can be used to sketch solutions to a differential equation. In particular, the slope field is a plot of a large collection of tangent lines to a large number of solutions of the differential equation, and we sketch a single solution by simply following these tangent lines. With a little more thought, we can use this same idea to approximate numerically the solutions of a differential equation.

Consider the initial value problem

\[ \frac{dy}{dt} = \frac12 (y + 1), \ y(0) = 0\text{.} \nonumber \]

a. Use the differential equation to find the slope of the tangent line to the solution \(y(t)\) at \(t=0\text{.}\) Then use the given initial value to find the equation of the tangent line at \(t=0\text{.}\)

b. Sketch the tangent line on the axes provided in Figure \(\PageIndex{1}\) on the interval \(0\leq t\leq 2\) and use it to approximate \(y(2)\text{,}\) the value of the solution at \(t=2\text{.}\)

c. Assuming that your approximation for \(y(2)\) is the actual value of \(y(2)\text{,}\) use the differential equation to find the slope of the tangent line to \(y(t)\) at \(t=2\text{.}\) Then, write the equation of the tangent line at \(t=2\text{.}\)

d. Add a sketch of this tangent line on the interval \(2\leq t\leq 4\) to your plot Figure \(\PageIndex{1}\); use this new tangent line to approximate \(y(4)\text{,}\) the value of the solution at \(t=4\text{.}\)

e. Repeat the same step to find an approximation for \(y(6)\text{.}\)

## Euler's Method

Preview Activity \(\PageIndex{1}\) demonstrates an algorithm known as Euler's^{ 1 } Method, which generates a numerical approximation to the solution of an initial value problem. In this algorithm, we will approximate the solution by taking horizontal steps of a fixed size that we denote by \(\Delta t\text{.}\)

Before explaining the algorithm in detail, let's remember how we compute the slope of a line: the slope is the ratio of the vertical change to the horizontal change, as shown in Figure \(\PageIndex{2}\).

In other words, \(m = \frac{\Delta y}{\Delta t}\text{.}\) Solving for \(\Delta y\text{,}\) we see that the vertical change is the product of the slope and the horizontal change, or

Now, suppose that we would like to solve the initial value problem

There is an algorithm by which we can find an algebraic formula for the solution to this initial value problem, and we can check that this solution is \(y(t) = t -1 + 2e^{-t}\text{.}\) But we are instead interested in generating an approximate solution by creating a sequence of points \((t_i, y_i)\text{,}\) where \(y_i\approx y(t_i)\text{.}\) For this first example, we choose \(\Delta t = 0.2\text{.}\)

Since we know that \(y(0) = 1\text{,}\) we will take the initial point to be \((t_0,y_0) = (0,1)\) and move horizontally by \(\Delta t = 0.2\) to the point \((t_1,y_1)\text{.}\) Thus, \(t_1=t_0+\Delta t = 0.2\text{.}\) Now, the differential equation tells us that the slope of the tangent line at this point is

so to move along the tangent line by taking a horizontal step of size \(\Delta t=0.2\text{,}\) we must also move vertically by

We then have the approximation \(y(0.2) \approx y_1= y_0 + \Delta y = 1 - 0.2 = 0.8\text{.}\) At this point, we have executed one step of Euler's method, as seen graphically in Figure \(\PageIndex{3}\).

Now we repeat this process: at \((t_1,y_1) = (0.2,0.8)\text{,}\) the differential equation tells us that the slope is

If we move forward horizontally by \(\Delta t\) to \(t_2=t_1+\Delta = 0.4\text{,}\) we must move vertically by

We consequently arrive at \(y_2=y_1+\Delta y = 0.8-0.12 = 0.68\text{,}\) which gives \(y(0.2)\approx 0.68\text{.}\) Now we have completed the second step of Euler's method, as shown in Figure \(\PageIndex{4}\).

If we continue in this way, we may generate the points \((t_i, y_i)\) shown in Figure \(\PageIndex{5}\). Because we can find a formula for the actual solution \(y(t)\) to this differential equation, we can graph \(y(t)\) and compare it to the points generated by Euler's method, as shown in Figure \(\PageIndex{6}\).

Because we need to generate a large number of points \((t_i,y_i)\text{,}\) it is convenient to organize the implementation of Euler's method in a table as shown. We begin with the given initial data.

\(t_i\) | \(y_i\) | \(dy/dt\) | \(\Delta y\) |
---|---|---|---|

\(0.0000\) | \(1.0000\) |

From here, we compute the slope of the tangent line \(m=dy/dt\) using the formula for \(dy/dt\) from the differential equation, and then we find \(\Delta y\text{,}\) the change in \(y\text{,}\) using the rule \(\Delta y = m\Delta t\text{.}\)

\(t_i\) | \(y_i\) | \(dy/dt\) | \(\Delta y\) |
---|---|---|---|

\(0.0000\) | \(1.0000\) | \(-1.0000\) | \(-0.2000\) |

Next, we increase \(t_i\) by \(\Delta t\) and \(y_i\) by \(\Delta y\) to get

\(t_i\) | \(y_i\) | \(dy/dt\) | \(\Delta y\) |
---|---|---|---|

\(0.0000\) | \(1.0000\) | \(-1.0000\) | \(-0.2000\) |

\(0.2000\) | \(0.8000\) |

We continue the process for however many steps we decide, eventually generating a table like Table \(\PageIndex{1}\).

\(t_i\) | \(y_i\) | \(dy/dt\) | \(\Delta y\) |
---|---|---|---|

\(0.0000\) | \(1.0000\) | \(-1.0000\) | \(-0.2000\) |

\(0.2000\) | \(0.8000\) | \(-0.6000\) | \(-0.1200\) |

\(0.4000\) | \(0.6800\) | \(-0.2800\) | \(-0.0560\) |

\(0.6000\) | \(0.6240\) | \(-0.0240\) | \(-0.0048\) |

\(0.8000\) | \(0.6192\) | \(0.1808\) | \(0.0362\) |

\(1.0000\) | \(0.6554\) | \(0.3446\) | \(0.0689\) |

\(1.2000\) | \(0.7243\) | \(0.4757\) | \(0.0951\) |

Consider the initial value problem

- Use Euler's method with \(\Delta t = 0.2\) to approximate the solution at \(t_i = 0.2, 0.4, 0.6, 0.8\text{,}\) and \(1.0\text{.}\) Record your work in the following table, and sketch the points \((t_i, y_i)\) on the axes provided.
Table \(\PageIndex{2}\). Table for recording results of Euler's method. \(t_i\) \(y_i\) \(dy/dt\) \(\Delta y\) \(0.0000\) \(0.0000\) \(0.2000\) \(0.4000\) \(0.6000\) \(0.8000\) \(1.0000\) - Find the exact solution to the original initial value problem and use this function to find the error in your approximation at each one of the points \(t_i\text{.}\)
- Explain why the value \(y_5\) generated by Euler's method for this initial value problem produces the same value as a left Riemann sum for the definite integral \(\int_0^1 (2t-1)~dt\text{.}\)
- How would your computations differ if the initial value was \(y(0) = 1\text{?}\) What does this mean about different solutions to this differential equation?

Consider the differential equation \(\frac{dy}{dt} = 6y-y^2\text{.}\)

- Sketch the slope field for this differential equation on the axes provided in Figure \(\PageIndex{8}\).
- Identify any equilibrium solutions and determine whether they are stable or unstable.
- What is the long-term behavior of the solution that satisfies the initial value \(y(0) = 1\text{?}\)
- Using the initial value \(y(0) = 1\text{,}\) use Euler's method with \(\Delta t = 0.2\) to approximate the solution at \(t_i = 0.2, 0.4, 0.6, 0.8\text{,}\) and \(1.0\text{.}\) Record your results in Table \(\PageIndex{3}\) and sketch the corresponding points \((t_i, y_i)\) on the axes provided in Figure \(\PageIndex{9}\). Note the different horizontal scale on the axes in Figure \(\PageIndex{9}\) compared to Figure \(\PageIndex{8}\).
Table \(\PageIndex{2}\). Table for recording results of Euler's method with \(\Delta t = 0.2\text{.}\) \(t_i\) \(y_i\) \(dy/dt\) \(\Delta y\) \(0.0\) \(1.0000\) \(0.2\) \(0.4\) \(0.6\) \(0.8\) \(1.0\) - What happens if we apply Euler's method to approximate the solution with \(y(0) = 6\text{?}\)

## The error in Euler's method

Since we are approximating the solutions to an initial value problem using tangent lines, we should expect that the error in the approximation will be smaller when the step size is smaller. Consider the initial value problem

whose solution we can easily find.

The question posed by this initial value problem is “what function do we know that is the same as its own derivative and has value 1 when \(t=0\text{?}\)” It is not hard to see that the solution is \(y(t) = e^t\text{.}\) We now apply Euler's method to approximate \(y(1) = e\) using several values of \(\Delta t\text{.}\) These approximations will be denoted by \(E_{\Delta t}\text{,}\) and we'll use them to see how accurate Euler's Method is.

To begin, we apply Euler's method with a step size of \(\Delta t = 0.2\text{.}\) In that case, we find that \(y(1) \approx E_{0.2} = 2.4883\text{.}\) The error is therefore

Repeatedly halving \(\Delta t\) gives the following results, expressed in both tabular and graphical form.

\(\Delta t\) | \(E_{\Delta t}\) | Error |
---|---|---|

\(0.200\) | \(2.4883\) | \(0.2300\) |

\(0.100\) | \(2.5937\) | \(0.1245\) |

\(0.050\) | \(2.6533\) | \(0.0650\) |

\(0.025\) | \(2.6851\) | \(0.0332\) |

Notice, both numerically and graphically, that the error is roughly halved when \(\Delta t\) is halved. This example illustrates the following general principle.

If Euler's method is used to approximate the solution to an initial value problem at a point \(\overline{t}\text{,}\) then the error is proportional to \(\Delta t\text{.}\) That is,

for some constant of proportionality \(K\text{.}\)

## Summary

- Euler's method is an algorithm for approximating the solution to an initial value problem by following the tangent lines while we take horizontal steps across the \(t\)-axis.
- If we wish to approximate \(y(\overline{t})\) for some fixed \(\overline{t}\) by taking horizontal steps of size \(\Delta t\text{,}\) then the error in our approximation is proportional to \(\Delta t\text{.}\)