Euler’s Method

Learning Outcomes

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

Consider the initial-value problem

[latex]{y}^{\prime }=2x - 3,y\left(0\right)=3[/latex].

 

Integrating both sides of the differential equation gives [latex]y={x}^{2}-3x+C[/latex], and solving for [latex]C[/latex] yields the particular solution [latex]y={x}^{2}-3x+3[/latex]. The solution for this initial-value problem appears as the parabola in Figure 10.

A graph over the range [-1,4] for x and y. The given upward opening parabola is drawn with vertex at (1.5, 0.75). Individual points are plotted at (0, 3), (0.5, 1.5), (1, 0.5), (1.5, 0), (2, 0), (2.5, 0.5), and (3, 1.5) with line segments connecting them.

Figure 10. Euler’s Method for the initial-value problem [latex]{y}^{\prime }=2x – 3,y\left(0\right)=3[/latex].

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 [latex]\left(0,3\right)[/latex]. 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 [latex]x[/latex] value by [latex]0.5[/latex] 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:

[latex]{y}^{\prime }={x}^{2}-{y}^{2},y\left(-1\right)=2[/latex].

 

The idea behind direction fields can also be applied to this problem to study the behavior of its solution. For example, at the point [latex]\left(-1,2\right)[/latex], the slope of the solution is given by [latex]y^{\prime} ={\left(-1\right)}^{2}-{2}^{2}=-3[/latex], so the slope of the tangent line to the solution at that point is also equal to [latex]-3[/latex]. Now we define [latex]{x}_{0}=-1[/latex] and [latex]{y}_{0}=2[/latex]. Since the slope of the solution at this point is equal to [latex]-3[/latex], we can use the method of linear approximation to approximate [latex]y[/latex] near [latex]\left(-1,2\right)[/latex].

[latex]L\left(x\right)={y}_{0}+{f}^{\prime }\left({x}_{0}\right)\left(x-{x}_{0}\right)[/latex].

 

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

[latex]\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}[/latex]

 

Now we choose a step size. The step size is a small value, typically [latex]0.1[/latex] or less, that serves as an increment for [latex]x[/latex]; it is represented by the variable [latex]h[/latex]. In our example, let [latex]h=0.1[/latex]. Incrementing [latex]{x}_{0}[/latex] by [latex]h[/latex] gives our next [latex]x[/latex] value:

[latex]{x}_{1}={x}_{0}+h=-1+0.1=-0.9[/latex].

 

We can substitute [latex]{x}_{1}=-0.9[/latex] into the linear approximation to calculate [latex]{y}_{1}[/latex].

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

 

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

[latex]\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}[/latex]

 

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

[latex]\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}[/latex]

 

Therefore the approximate value of the solution to the differential equation is [latex]y=1.492[/latex] when [latex]x=-0.8[/latex].

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.

Using Euler’s Method to Approximate Solutions to a Differential Equation
[latex]n[/latex] [latex]0[/latex] [latex]1[/latex] [latex]2[/latex] [latex]3[/latex] [latex]4[/latex] [latex]5[/latex]
[latex]{x}_{n}[/latex] [latex]-1[/latex] [latex]-0.9[/latex] [latex]-0.8[/latex] [latex]-0.7[/latex] [latex]-0.6[/latex] [latex]-0.5[/latex]
[latex]{y}_{n}[/latex] [latex]2[/latex] [latex]1.7[/latex] [latex]1.492[/latex] [latex]1.3334[/latex] [latex]1.2046[/latex] [latex]1.0955[/latex]
[latex]n[/latex] [latex]6[/latex] [latex]7[/latex] [latex]8[/latex] [latex]9[/latex] [latex]10[/latex]
[latex]{x}_{n}[/latex] [latex]-0.4[/latex] [latex]-0.3[/latex] [latex]-0.2[/latex] [latex]-0.1[/latex] [latex]0[/latex]
[latex]{y}_{n}[/latex] [latex]1.0004[/latex] [latex]1.9164[/latex] [latex]1.8414[/latex] [latex]1.7746[/latex] [latex]1.7156[/latex]

Euler’s Method


Consider the initial-value problem

[latex]y^{\prime} =f\left(x,y\right),y\left({x}_{0}\right)={y}_{0}[/latex].

 

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

[latex]\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}[/latex]

 

Here [latex]h>0[/latex] represents the step size and [latex]n[/latex] is an integer, starting with [latex]1[/latex]. The number of steps taken is counted by the variable [latex]n[/latex].

Typically [latex]h[/latex] is a small value, say [latex]0.1[/latex] or [latex]0.05[/latex]. The smaller the value of [latex]h[/latex], the more calculations are needed. The higher the value of [latex]h[/latex], the fewer calculations are needed. However, the tradeoff results in a lower degree of accuracy for larger step size, as illustrated in Figure 11.

Two graphs of the same parabola, y = x ^ 2 – 3 x + 3. The first shows Euler’s method for the given initial-value problem with a step size of h = 0.05, and the second shows Euler’s method with a step size of h = 0.25. The first then has the points (0, 3), (.5, 1.5), (1, 0.5), (1.5, 0), (2, 0), (2.5, 0.5), and (3, 1.5) plotted with line segments connecting them. The second has the points (0, 3), (0.25, 2.25), (0.5, 1.625), (0.75, 1.125), (1, 0.75), (1.25, 0.5), (1.5, 0.375), (2, 0.5), (2.25, 0.75), (2.5, 1.125), (2.75, 1.625), and (3, 2.25) plotted with line segments connecting them.

Figure 11. Euler’s method for the initial-value problem [latex]{y}^{\prime }=2x – 3,y\left(0\right)=3[/latex] with (a) a step size of [latex]h=0.5[/latex]; and (b) a step size of [latex]h=0.25[/latex].

Example: Using Euler’s Method

Consider the initial-value problem

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

 

Use Euler’s method with a step size of [latex]0.1[/latex] to generate a table of values for the solution for values of [latex]x[/latex] between [latex]0[/latex] and [latex]1[/latex].

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.

You can view the transcript for this segmented clip of “4.2.3” here (opens in new window).

Key Takeaways

Consider the initial-value problem

[latex]{y}^{\prime }={x}^{3}+{y}^{2},y\left(1\right)=-2[/latex].

 

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

Try It