← Back to Math 055

9.1 Euler Methods and Error Analysis: Class Notes

9.1a

Definition

Because Euler’s method, which uses the iterative formula yn+1=yn+hf(xn,yn), n=0,1,2,… to approximate solutions to initial-value problems of the form y′=f(x,y), y(x0)=y0, uses approximations, the y-values obtained this way contain local truncation error at each step in the approximation.

To determine an upper bound for the size of the error, consider the following. Suppose a function y(x) possesses k+1 derivatives that are continuous on an open interval containing a and x. The kth-degree Taylor polynomial with remainder for y(x) is

y(x)=y(a)+y′(a)x−a1!+⋯+y(k)(a)(x−a)kk!+y(k+1)(c)(x−a)k+1(k+1)!

where c is some value between a and x. For k=1, a=x0, and x=xn+1=xn+h, we have

y(xn+1)=y(xn)+y′(xn)h1!+y″(c)h22!

This is precisely the formula for Euler’s method plus a remainder term. Thus, the local truncation error in yn+1 is y″(c)h22!, where xn<c<xn+1. Since we typically don’t know the value of c, an upper bound for the absolute value of the error is Mh2/2, where M≥|y″(x)|, xn<x<xn+1. We can use the notation O(h2) to indicate that the magnitude of the error depends on h2. (This is called “big oh” notation, and it essentially indicates that one quantity is bounded by another quantity.)

The first part of the right side is the Taylor polynomial, and the last term is the remainder.

Definition

The total error in approximating yn+1 contains local truncation error at each step, and so the result after multiple iterations contains global truncation error.

It can be shown that global truncation error using Euler’s method is O(h).

The improved Euler’s method uses an average of two slopes and has a local truncation error O(h3) and global truncation error O(h2).

Improved Euler’s method

First, we use Euler’s method to obtain yn+1*=yn+hf(xn,yn). This is a predictor step.

Then we use yn+1=yn+hf(xn,yn)+f(xn+1,yn+1*)2. This is a corrector step.

Because of the two-step process, this is called a predictor-corrector method.

Euler’s method (from Section 2.6): each step follows the tangent line.

Euler's method: one step along the tangent line at (x0, y0) lands below the solution curve

Euler’s method. A solution curve (in blue) passes through (x0,y0). The tangent line L(x) at that point has slope f(x0,y0). Moving a step h to x1=x0+h along the tangent line gives the approximation (x1,y1), while the curve itself is at (x1,y(x1)). The vertical gap between those two points is the error.

Improved Euler’s method: each step follows a line whose slope is the average of two slopes.

Improved Euler's method: the step uses the average of the slopes at (x0, y0) and (x1, y1 star)

Improved Euler’s method. From (x0,y0) on the solution curve, the tangent line with slope m0=f(x0,y0) predicts the point (x1,y1*). A short line through that point has slope m1=f(x1,y1*). The dashed line from (x0,y0) has the average slope mave=f(x0,y0)+f(x1,y1*)2 and gives the corrected point (x1,y1), much closer to the curve’s point (x1,y(x1)) than the prediction.

9.1b

Example

Use the improved Euler’s method to obtain a four-decimal approximation of the indicated value. First use h=0.1 and then use h=0.05.

y′=4x−2y,y(0)=2;y(0.5)

Solution

h=0.1: start with x0=0 and y0=2. Predictor:

y1*=y0+hf(x0,y0)=2+0.1(4(0)−2(2))=1.6

Corrector, with x1=0.1 and the predicted value y1*=1.6 used in the second slope f(x1,y1*):

y1=y0+h2[f(x0,y0)+f(x1,y1*)]=2+0.12[4(0)−2(2)+4(0.1)−2(1.6)]=1.66

Then the next predictor starts from y1=1.66, and gives y2 the same way:

y2*=1.66+0.1(4(0.1)−2(1.66))=1.368 ⇒ y2

Continuing in a spreadsheet (each row uses yn to predict yn+1*, and the next row’s yn+1 uses both slopes):

Improved Euler’s method with h = 0.1
nxnynf(xn,yn)yn+1*f(xn+1,yn+1*)
002−41.6−2.8
10.11.66−2.921.368−1.936
20.21.4172−2.03441.21376−1.22752
30.31.254104−1.3082081.1232832−0.6465664
40.41.1563653−0.71273061.0850922−0.1701844
50.51.1122195

Answer: y(0.5)≈1.1122(h=0.1)

Improved Euler’s method with h = 0.05
nxnynf(xn,yn)yn+1*f(xn+1,yn+1*)
002−41.8−3.4
10.051.815−3.431.6435−2.887
20.11.657075−2.914151.5113675−2.422735
30.151.5236529−2.44730571.4012876−2.0025752
40.21.4124059−2.02481171.3111653−1.6223305
50.251.3212273−1.64245461.2391046−1.2782091
60.31.2482107−1.29642141.1833896−0.9667793
70.351.1916307−0.98326141.1424676−0.6849352
80.41.1499258−0.69985151.1149332−0.4298664
90.451.1216828−0.44336561.0995145−0.1990291
100.51.105623

Answer: y(0.5)≈1.1056(h=0.05)

Compare with the actual values from the analytic solution y=3e−2x+2x−1 (found below):

Errors with h = 0.1
xnynActual valueAbs. error% Rel. error
02200%
0.11.661.65619230.00380770.23%
0.21.41721.41096010.00623990.44%
0.31.2541041.24643490.00766910.62%
0.41.15636531.14798690.00837840.73%
0.51.11221951.10363830.00858120.78%
Errors with h = 0.05
xnynActual valueAbs. error% Rel. error
02200%
0.051.8151.81451230.00048770.03%
0.11.6570751.65619230.00088270.05%
0.151.52365291.52245470.00119820.08%
0.21.41240591.41096010.00144570.10%
0.251.32122731.3195920.00163530.12%
0.31.24821071.24643490.00177580.14%
0.351.19163071.18975590.00187480.16%
0.41.14992581.14798690.00193890.17%
0.451.12168281.1197090.00197380.18%
0.51.1056231.10363830.00198460.18%

Note that h→12h makes the error about 14 as large: at x=0.5, the absolute error drops from 0.0085812 to 0.0019846 (and the relative error from 0.78% to 0.18%). The error is O(h2).

Analytic solution: y′+2y=4x, y(0)=2.

Tip: The equation is linear, so an integrating factor μ works, as do the auxiliary equation (with undetermined coefficients) and Laplace transforms. Two of these are shown.

Using the auxiliary equation, m=−2, so yc=ce−2x. Try yp=Ax+B, so yp′=A:

A+2Ax+2B=4x ⇒ A=2, B=−1y=ce−2x+2x−1y(0)=2 ⇒ 2=c−1 ⇒ c=3

Or, with the integrating factor μ=e2x:

ddx(e2xy)=4xe2xe2xy=2xe2x−e2x+cy=2x−1+ce−2x

and y(0)=2 again gives c=3.

Answer: y=3e−2x+2x−1