Direction Fields and Euler’s Method: Learn It 4

Euler’s Method

Sometimes you need to find approximate solutions to differential equations that are difficult or impossible to solve analytically. Euler’s Method provides a systematic approach for finding these numerical approximations using the concept of linear approximation.

Let’s start with a simple example to see how this works.

Consider the initial-value problem:

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

We can solve this exactly by integrating: [latex]y = x^2 - 3x + C[/latex].

Using the initial condition gives us [latex]y = x^2 - 3x + 3[/latex].

The solution for this initial-value problem appears as the parabola in the figure below.

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. Notice how the process works:

  • Start at the initial value [latex](0, 3)[/latex]
  • Use the differential equation to find the slope at each point
  • Move forward by a fixed step size (here [latex]0.5[/latex])
  • Draw a line segment with that slope

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.

Let’s work through a more complex example that we can’t solve analytically:

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

At the point [latex](-1, 2)[/latex], the slope of the solution is [latex]y^{\prime} = (-1)^2 - (2)^2 = -3[/latex]. We define [latex]x_0 = -1[/latex] and [latex]y_0 = 2[/latex]. Since the slope at this point equals [latex]-3[/latex], we can use linear approximation to approximate [latex]y[/latex] near [latex](-1, 2)[/latex]:

[latex]L(x) = y_0 + f'(x_0)(x - x_0)[/latex]

Here [latex]x_0 = -1[/latex], [latex]y_0 = 2[/latex], and [latex]f'(x_0) = -3[/latex], so the linear approximation becomes:

[latex]L(x) = 2 + (-3)(x - (-1)) = 2 - 3x - 3 = -3x - 1[/latex]

Now we choose a step size [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 substitute [latex]x_1 = -0.9[/latex] into the linear approximation to calculate [latex]y_1[/latex]:

[latex]y_1 = L(x_1) = -3(-0.9) - 1 = 1.7[/latex]

Therefore the approximate [latex]y[/latex] value for the solution when [latex]x = -0.9[/latex] is [latex]y = 1.7[/latex].

We 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 [latex]y^{\prime} = (-0.9)^2 - (1.7)^2 = -2.08[/latex].

First, [latex]x_2 = x_1 + h = -0.9 + 0.1 = -0.8[/latex]. Using linear approximation:

[latex]L(x) = y_1 + f'(x_1)(x - x_1) = 1.7 + (-2.08)(x - (-0.9)) = 1.7 - 2.08x - 1.872 = -2.08x - 0.172[/latex]

Finally, we substitute [latex]x_2 = -0.8[/latex] into the linear approximation:

[latex]y_2 = L(x_2) = -2.08(-0.8) - 0.172 = 1.492[/latex]

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

This is the idea behind Euler’s Method. Repeating these steps gives us the following approximations:

[latex]n[/latex] [latex]x_n[/latex] [latex]y_n[/latex]
[latex]0[/latex] [latex]-1[/latex] [latex]2[/latex]
[latex]1[/latex] [latex]-0.9[/latex] [latex]1.7[/latex]
[latex]2[/latex] [latex]-0.8[/latex] [latex]1.492[/latex]
[latex]3[/latex] [latex]-0.7[/latex] [latex]1.3334[/latex]
[latex]4[/latex] [latex]-0.6[/latex] [latex]1.2046[/latex]
[latex]5[/latex] [latex]-0.5[/latex] [latex]1.0955[/latex]
[latex]6[/latex] [latex]-0.4[/latex] [latex]1.0004[/latex]
[latex]7[/latex] [latex]-0.3[/latex] [latex]0.9164[/latex]
[latex]8[/latex] [latex]-0.2[/latex] [latex]0.8414[/latex]
[latex]9[/latex] [latex]-0.1[/latex] [latex]0.7746[/latex]
[latex]10[/latex] [latex]0[/latex] [latex]0.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].

Choosing Step Size[latex]\\[/latex]Typically use [latex]h = 0.1[/latex] or [latex]h = 0.05[/latex]. Smaller step sizes give more accurate results but require more computation. The tradeoff between accuracy and efficiency is illustrated below.

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

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