Topic 14.1: Euler's Method

Contents Previous Chapter Start of Chapter No Previous Topic Introduction Notes Theory HOWTO Examples Engineering Error Questions Matlab Maple Next Topic Next Chapter

Euler's method is an easy method for solving an initial-value problem numerically. It's error properties are not very good, however, we will take this technique and improve on it with Heun's method and various higher-order improvements.

The pronunciation of the Euler's is equivalent to Oilers, as in the Edmonton Oilers.

.

Background

Useful background for this topic includes:

References

Interactive Maplet

A Demonstration of Euler's Method

Theory


An initial value problem is a first-order ordinary differential equation

y(1)(t) = f(t, y(t))

together with an initial condition

y(t0) = y0

We will assume that the differential equation can be written in the above form, which is true in many cases in practice.

We are trying to find a function y(t), the derivative of which satisfies the first equation, and when we evaluate the function at t0, it evaluates to y0.

We know that a continuous function can be approximated by a straight line, at least, locally, so if we have the slope of the function (it's given to us by the equation y(1)(t) = f(t, y(t)) ), why not approximate the function by this line. The equation of this line is y0 + f(t0, y0) (t - t0)

Therefore, if we want to approximate y(t1), we can just evaluate the straight line to get:

y(t1) ≈ y0 + f(t0, y0) (t1 - t0)

If we denote h = t1t0, then this simplifies to:

y(t1) ≈ y0 + h f(t0, y0)

We will denote this approximation by y1.

Graphical Representation

To visualize this, consider the first-order ODE

y(1)(t) = y(t) - t + 1

Let's pick a 21 × 21 grid of points on (t, y) ∈ [0, 4] × [-1, 3] and evaluate the slope at those points. Next, plot an arrow with the slope at that point. This is shown in Figure 1.

Figure 1. The slopes defined by the given ODE for various values of t and y.

Thus, a solution which passes through (or close to) one of the given points must have a slope equal to (or close to) the slope of the arrow.

Figure 2. Four solutions given four different initial conditions.

You can almost draw the solutions in by hand, simply by following the arrows. Figure 2 shows four separate initial conditions: y(0) = -0.5, y(0) = 0, y(0) = 0.5, and y(0) = 1. Note how each solution has, in all cases, a slope which closely matches any arrows which it may pass?

Example

Thus, suppose we start with the initial condition y(0) = 0.5. If we want to approximate y(1) for the solution which has the initial condition y(0) = 0.5, why not follow the slope at (0, 0.5) out a distance 1. This is demonstrated in Figure 3.

Figure 3. Approximating y(1) using the initial condition y(0) = 0.5 and the slope at that point.

This gives us an approximate value of y(1) ≈ 0.5 + 1.5⋅1 = 2.

We can find (using calculus) that the actual solution is y(t) = t + ½et. First, we note that y(0) = 0 + ½e0 = 0.5, and thus this function satisfies the initial condition, but also, if we differentiate it, we get that y(1)(t) = 1 + ½et. If we rewrite this as y(1)(t) = 1 − t + (t ½et), we note that the object in the brackets is y(t), and therefore y(1)(t) = 1 − t + y(t), which is the differential equation we started with.

Therefore, the approximation y(1) ≈ 2 is not close, but is not unreasonably far from the correct answer of 2.35914.


HOWTO


Problem

Given the IVP

y(1)(t) = f( t, y(t) )
y(t0) = y0

approximate y(t1).

Assumptions

The function f(t, y) should be continuous in both variables.

Tools

We will use Taylor series.

Initial Conditions

Set h = t1 - t0. Let y1 be the approximation of y(t1).

Process

Let y1 = y0 + h f( t0, y0 ).


Examples


Example 1

Given the IVP y(1)(t) = 1 - t y(t) with y(0) = 1, approximate y(1) with one step.

First, let t0 = 0, y0 = 1, and h = 1. Therefore our approximation is y1 = y0 + h(1 - t0 y0) = 1 + 1 (1 - 0⋅1) = 2. The actual value is 1.331309118 and therefore the absolute error is approximately 0.669.

Example 2

Given the same IVP shown in Example 1, approximate y(0.5).

First, let t0 = 0, y0 = 1, and h = 0.5. Therefore our approximation is y1 = y0 + h(1 - t0 y0) = 1 + 0.5 (1 - 0⋅1) = 1.5. The actual value is 1.342841185 and therefore the error is 0.157, or approximately 1/4 the error in Example 1.

Example 3

Repeat Examples 1 and 2 but with with the initial value y(0.5) = 2.5 and approximating y(1.5) and y(1.0).

First, let t0 = 0.5, y0 = 2.5, and h = 1. Therefore our approximation is y1 = y0 + h(1 - t0 y0) = 2.5 + 1 (1 - 0.5 ⋅ 2.5) = 2.25. The actual value is 1.502483616 and therefore the absolute error is approximately 0.748.

Next, let t0 = 0.5, y0 = 2.5, and h = 0.5. Therefore our approximation is y1 = y0 + h(1 - t0 y0) = 2.5 + 0.5 (1 - 0.5 ⋅ 2.5) = 2.375. The actual value is 2.126611964 and therefore the absolute error is approximately 0.248.

In this case, the error is not exactly 1/4, but if we shrink the interval by half again, approximating y(0.75):

t0 = 0.5, y0 = 2.5, and h = 0.25. Therefore our approximation is y1 = y0 + h(1 - t0 y0) = 2.5 + 0.25 (1 - 0.5 ⋅ 2.5) = 2.4375. The actual value is 2.368609584 and therefore the absolute error is approximately 0.0689, which is closer to 1/4 the error found when approximating y(1).

If we tabulate the errors for various values of h, as is shown in Table 1, we note that as h gets smaller, the error drops by almost exactly 1/4 each time we divide h by two.

Table 1. Errors when approximating y(t0 + h) for decreasing values of h.

hApproximation
of y(0.5 + h)
Error
12.250.748
0.52.3750.248
0.252.43750.0689
0.1252.468750.0179
0.06252.4843750.00457
0.031252.49218750.00115
0.0156262.496093750.000289
0.00781252.4980468750.0000723

Engineering


To be completed.


Error


To determine the error for Euler's method, we need look no further than the Taylor series:

We know, from the IVP, that y(1)(t) = f(t, y(t)), and therefore the error is the other term: ½ y(2)(τ)h2 where τ ∈ [tt + h].

Thus, the error is O(h2). As with Newton's method, the knowledge of the derivative gives us this formula.

To demonstrate, consider y(1)(t) = t y(t) − y(t) + t − 1 with the initial value y(0) = 1. We may approximate y(0.1) by setting y0 = y(0) and calculating y1 = y0 + 0.1 f(0, 1) = 1 − 2 ⋅ 0.1 = 0.8.

The actual answer is 0.8187458691, and to check this, we can use implicit differentiation:

We can substitute y(1)(τ) into this formula to get (after simplification):

We know that τ ∈ [0, 0.1] and if we assume that y(τ) ∈ [0.8, 1], then we get that the second derivative is bounded by [3.258, 4]. Thus, the error should be ½ y(2)(τ) 0.12 ∈ [0.01629, 0.02]. We found above that the error was 0.01875 which is approximately in the middle of this interval.


Questions


Question 1

Given the IVP

y(1)(t) = 1 - 0.25 y(t) + 0.2 t
y(0) = 1

approximate y(0.5), y(1), and y(1.5) using Euler's method.

Answer: 1.375, 1.750, 2.125.

Question 2

Given the same ODE as in Question 1, but with the initial condition y(1) = 2, approximate y(1.5) and y(2.0).

Answer: 2.35 and 2.7

Question 3

Given an IVP with an initial condition y(0) = y0, if the second derivative is bounded by -8 < y(2)(t) < 8, on how large an interval can we estimate y(t) if we want to ensure that the error is less than 0.0001?

Answer: (-0.005, 0.005).


Matlab


To be completed later.


Maple


Given the IVP y(1)(t = t y(t) - t2 + 1 with y(0) = 3, to approximate y(1), we can do:

t[0] := 0;
t[1] := 1;
y[0] := 3;
f := (t, y) -> t*y - t^2 + 1;
h := t[1] - t[0];
y[1] := y[0] + h*f(t[0], y[0]);


Copyright ©2005 by Douglas Wilhelm Harder. All rights reserved.