Active Calculus · 7: Differential Equations

7.3: Euler's Method

Motivating Questions
  • 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.

Preview Activity 7.3.17.3.1

Consider the initial value problem

dydt=12(y+1), y(0)=0. \frac{dy}{dt} = \frac12 (y + 1), \ y(0) = 0\text{.}

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

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

7_3_PA.svg

Figure 7.3.17.3.1. Grid for plotting the tangent line.

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

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

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

Preview Activity 7.3.17.3.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 Δt.\Delta t\text{.}

“Euler” is pronounced “Oy-ler.” Among other things, Euler is the mathematician credited with the famous number e;e\text{;} if you incorrectly pronounce his name “You-ler,” you fail to appreciate his genius and legacy.

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

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

Δy=mΔt. \Delta y = m\Delta t\text{.}
 
7_3_slope.svgFigure 7.3.27.3.2. The role of slope in Euler's Method.

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

dydt=t−y, y(0)=1. \frac{dy}{dt} = t - y, \ y(0) = 1\text{.}

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.y(t) = t -1 + 2e^{-t}\text{.} But we are instead interested in generating an approximate solution by creating a sequence of points (ti,yi),(t_i, y_i)\text{,} where yi≈y(ti).y_i\approx y(t_i)\text{.} For this first example, we choose Δt=0.2.\Delta t = 0.2\text{.}

Since we know that y(0)=1,y(0) = 1\text{,} we will take the initial point to be (t0,y0)=(0,1)(t_0,y_0) = (0,1) and move horizontally by Δt=0.2\Delta t = 0.2 to the point (t1,y1).(t_1,y_1)\text{.} Thus, t1=t0+Δt=0.2.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

m=dydt∣(0,1)=0−1=−1, m=\frac{dy}{dt}\bigg\vert_{(0,1)} = 0-1 = -1\text{,}

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

Δy=mΔt=−1⋅0.2=−0.2. \Delta y = m\Delta t = -1\cdot 0.2 = -0.2\text{.}

We then have the approximation y(0.2)≈y1=y0+Δy=1−0.2=0.8.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 7.3.37.3.3.

 

7_3_euler_points_1.svgFigure 7.3.37.3.3. One step of Euler's method.

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

m=dydt∣(0.2,0.8)=0.2−0.8=−0.6. m=\frac{dy}{dt}\bigg\vert_{(0.2,0.8)} = 0.2-0.8 = -0.6\text{.}

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

Δy=−0.6⋅0.2=−0.12. \Delta y = -0.6\cdot0.2 = -0.12\text{.}

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

 

7_3_euler_points_2.svgFigure 7.3.47.3.4. Two steps of Euler's method.

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

7_3_euler_points_6.svg
Figure 7.3.57.3.5: The points and piecewise linear approximate solution generated by Euler's method.
7_3_euler.svg
Figure 7.3.67.3.6: The approximate solution compared to the exact solution (shown in blue).

Because we need to generate a large number of points (ti,yi),(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.

tit_i yiy_i dy/dtdy/dt Δy\Delta y
0.00000.0000 1.00001.0000    

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

tit_i yiy_i dy/dtdy/dt Δy\Delta y
0.00000.0000 1.00001.0000 −1.0000-1.0000 −0.2000-0.2000

Next, we increase tit_i by Δt\Delta t and yiy_i by Δy\Delta y to get

tit_i yiy_i dy/dtdy/dt Δy\Delta y
0.00000.0000 1.00001.0000 −1.0000-1.0000 −0.2000-0.2000
0.20000.2000 0.80000.8000    

We continue the process for however many steps we decide, eventually generating a table like Table 7.3.17.3.1.

Table 7.3.17.3.1. Euler's method for 6 steps with Δt=0.2.\Delta t = 0.2\text{.}
tit_i yiy_i dy/dtdy/dt Δy\Delta y
0.00000.0000 1.00001.0000 −1.0000-1.0000 −0.2000-0.2000
0.20000.2000 0.80000.8000 −0.6000-0.6000 −0.1200-0.1200
0.40000.4000 0.68000.6800 −0.2800-0.2800 −0.0560-0.0560
0.60000.6000 0.62400.6240 −0.0240-0.0240 −0.0048-0.0048
0.80000.8000 0.61920.6192 0.18080.1808 0.03620.0362
1.00001.0000 0.65540.6554 0.34460.3446 0.06890.0689
1.20001.2000 0.72430.7243 0.47570.4757 0.09510.0951
Activity 7.3.27.3.2

Consider the initial value problem

dydt=2t−1, y(0)=0 \frac{dy}{dt} = 2t-1, \ y(0) = 0
  1. Use Euler's method with Δt=0.2\Delta t = 0.2 to approximate the solution at ti=0.2,0.4,0.6,0.8,t_i = 0.2, 0.4, 0.6, 0.8\text{,} and 1.0.1.0\text{.} Record your work in the following table, and sketch the points (ti,yi)(t_i, y_i) on the axes provided.
    Table 7.3.27.3.2. Table for recording results of Euler's method.
    tit_i yiy_i dy/dtdy/dt Δy\Delta y
    0.00000.0000 0.00000.0000    
    0.20000.2000      
    0.40000.4000      
    0.60000.6000      
    0.80000.8000      
    1.00001.0000      
    7_3_euler_empty.svg
    Figure 7.3.77.3.7. Grid for plotting points generated by Euler's method.
  2. 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 ti.t_i\text{.}
  3. Explain why the value y5y_5 generated by Euler's method for this initial value problem produces the same value as a left Riemann sum for the definite integral ∫01(2t−1) dt.\int_0^1 (2t-1)~dt\text{.}
  4. How would your computations differ if the initial value was y(0)=1?y(0) = 1\text{?} What does this mean about different solutions to this differential equation?
Activity 7.3.37.3.3

Consider the differential equation dydt=6y−y2.\frac{dy}{dt} = 6y-y^2\text{.}

  1. Sketch the slope field for this differential equation on the axes provided in Figure 7.3.87.3.8.
    7_3_slopefield.svg

    Figure 7.3.87.3.8. Grid for plotting the slope field of the given differential equation.

  2. Identify any equilibrium solutions and determine whether they are stable or unstable.
  3. What is the long-term behavior of the solution that satisfies the initial value y(0)=1?y(0) = 1\text{?}
  4. Using the initial value y(0)=1,y(0) = 1\text{,} use Euler's method with Δt=0.2\Delta t = 0.2 to approximate the solution at ti=0.2,0.4,0.6,0.8,t_i = 0.2, 0.4, 0.6, 0.8\text{,} and 1.0.1.0\text{.} Record your results in Table 7.3.37.3.3 and sketch the corresponding points (ti,yi)(t_i, y_i) on the axes provided in Figure 7.3.97.3.9. Note the different horizontal scale on the axes in Figure 7.3.97.3.9 compared to Figure 7.3.87.3.8.
    Table 7.3.27.3.2. Table for recording results of Euler's method with Δt=0.2.\Delta t = 0.2\text{.}
    tit_i yiy_i dy/dtdy/dt Δy\Delta y
    0.00.0 1.00001.0000    
    0.20.2      
    0.40.4      
    0.60.6      
    0.80.8      
    1.01.0      
    7_3_euler_empty_2.svg
    Figure 7.3.97.3.9. Axes for plotting the results of Euler's method.
  5. What happens if we apply Euler's method to approximate the solution with y(0)=6?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

dydt=y, y(0)=1, \frac{dy}{dt} = y, \ y(0) = 1\text{,}

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?t=0\text{?}” It is not hard to see that the solution is y(t)=et.y(t) = e^t\text{.} We now apply Euler's method to approximate y(1)=ey(1) = e using several values of Δt.\Delta t\text{.} These approximations will be denoted by EΔt,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 Δt=0.2.\Delta t = 0.2\text{.} In that case, we find that y(1)≈E0.2=2.4883.y(1) \approx E_{0.2} = 2.4883\text{.} The error is therefore

y(1)−E0.2=e−2.4883≈0.2300. y(1) - E_{0.2} = e - 2.4883 \approx 0.2300\text{.}

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

Table 7.3.37.3.3. Errors that correspond to different Δt\Delta t values.
Δt\Delta t EΔtE_{\Delta t} Error
0.2000.200 2.48832.4883 0.23000.2300
0.1000.100 2.59372.5937 0.12450.1245
0.0500.050 2.65332.6533 0.06500.0650
0.0250.025 2.68512.6851 0.03320.0332
7_3_error.svg
Figure 7.3.107.3.10. A plot of the error as a function of Δt.\Delta t\text{.}

Notice, both numerically and graphically, that the error is roughly halved when Δt\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 t‾,\overline{t}\text{,} then the error is proportional to Δt.\Delta t\text{.} That is,

y(t‾)−EΔt≈KΔt y(\overline{t}) - E_{\Delta t} \approx K\Delta t

for some constant of proportionality K.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 tt-axis.
  • If we wish to approximate y(t‾)y(\overline{t}) for some fixed t‾\overline{t} by taking horizontal steps of size Δt,\Delta t\text{,} then the error in our approximation is proportional to Δt.\Delta t\text{.}

Credit and licence

This page titled 7.3: Euler's Method was last modified on Fri, 29 Sep 2023 00:42:50 GMT and is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Matthew Boelkins, David Austin, and Steven Schlicker ( ScholarWorks @Grand Valley State University ) via source content that was edited to the style and standards of the LibreTexts platform.

Source: https://math.libretexts.org/Bookshelves/Calculus/Active_Calculus_(Boelkins_et_al.)/07%3A_Differential_Equations/7.03%3A_Euler's_Method

Licence: CC BY-SA 4.0 (creativecommons.org/licenses/by-sa/4.0/). You may share and adapt it under the same licence, with this credit. WorldClass adapted the formatting only: the text is the authors', with interactive parts and links to other sites left out.

Build status · Flash Infinity AI™ is a trademark of AI-Flash Inc.. WorldClass is not affiliated with, approved or accredited by any exam board, curriculum provider or university unless a page says so.