6.1 Euler Methods and Error Analysis

INTRODUCTION

In Section 2.6 we examined one of the simplest numerical methods for approximating solutions of first-order initial-value problems y′ = f(x, y), y(x0) = y0. Recall that the backbone of Euler’s method was the formula

(1)

where f is the function obtained from the differential equation y′ = f(x, y). The recursive use of (1) for n = 0, 1, 2, . . . yields the y-coordinates y1, y2, y3, . . . of points on successive “tangent lines” to the solution curve at x1, x2, x3, . . . or xn = x0 + nh, where h is a constant and is the size of the step between xn and xn + 1. The values y1, y2, y3, . . . approximate the values of a solution y(x) of the IVP at x1, x2, x3, . . . . But whatever advantage (1) has in its simplicity is lost in the crudeness of its approximations.

A Comparison

In Problem 4 in Exercises 2.6 you were asked to use Euler’s method to obtain the approximate value of y(1.5) for the solution of the initial-value problem y′ = 2xy, y(1) = 1. You should have obtained the analytic solution and results similar to those given in Tables 6.1.1 and 6.1.2.

TABLE 6.1.1 Euler’s Method with h = 0.1
The table captioned Euler’s Method with h equals 0.1 has five columns and six rows. The column headings are as follows: Column 1, x subscript n. Column 2, y subscript n. Column 3, Actual Value. Column 4, Absolute Error. Column 5, Percentage Relative Error. The row entries are as follows: Row 1. x subscript n, 1.00. y subscript n, 1.0000. Actual Value, 1.0000. Absolute Error, 0.0000. Percentage Relative Error, 0.00. Row 2. x subscript n, 1.10. y subscript n, 1.2000. Actual Value, 1.2337. Absolute Error, 0.0337. Percentage Relative Error, 2.73. Row 3. x subscript n, 1.20. y subscript n, 1.4640. Actual Value, 1.5527. Absolute Error, 0.0887. Percentage Relative Error, 5.71. Row 4. x subscript n, 1.30. y subscript n, 1.8154. Actual Value, 1.9937. Absolute Error, 0.1784. Percentage Relative Error, 8.95. Row 5. x subscript n, 1.40. y subscript n, 2.2874. Actual Value, 2.6117. Absolute Error, 0.3244. Percentage Relative Error, 12.42. Row 6. x subscript n, 1.50. y subscript n, 2.9278. Actual Value, 3.4903. Absolute Error, 0.5625. Percentage Relative Error, 16.12.
TABLE 6.1.2 Euler’s Method with h = 0.05
The table captioned Euler’s Method with h equals 0.05 has five columns and eleven rows. The column headings are as follows: Column 1, x subscript n. Column 2, y subscript n. Column 3, Actual Value. Column 4, Absolute Error. Column 5, Percentage Relative Error. The row entries are as follows: Row 1. x subscript n, 1.00. y subscript n, 1.0000. Actual Value, 1.0000. Absolute Error, 0.0000. Percentage Relative Error, 0.00. Row 2. x subscript n, 1.05. y subscript n, 1.1000. Actual Value, 1.1079. Absolute Error, 0.0079. Percentage Relative Error, 0.72. Row 3. x subscript n, 1.10. y subscript n, 1.2155. Actual Value, 1.2337. Absolute Error, 0.0182. Percentage Relative Error, 1.47. Row 4. x subscript n, 1.15. y subscript n, 1.3492. Actual Value, 1.3806. Absolute Error, 0.0314. Percentage Relative Error, 2.27. Row 5. x subscript n, 1.20. y subscript n, 1.5044. Actual Value, 1.5527. Absolute Error, 0.0483. Percentage Relative Error, 3.11. Row 6. x subscript n, 1.25. y subscript n, 1.6849. Actual Value, 1.7551. Absolute Error, 0.0702. Percentage Relative Error, 4.00. Row 7. x subscript n, 1.30. y subscript n, 1.8955. Actual Value, 1.9937. Absolute Error, 0.0982. Percentage Relative Error, 4.93. Row 8. x subscript n, 1.35. y subscript n, 2.1419. Actual Value, 2.2762. Absolute Error, 0.1343. Percentage Relative Error, 5.90. Row 9. x subscript n, 1.40. y subscript n, 2.4311. Actual Value, 2.6117. Absolute Error, 0.1806. Percentage Relative Error, 6.92. Row 10. x subscript n, 1.45. y subscript n, 2.7714. Actual Value, 3.0117. Absolute Error, 0.2403. Percentage Relative Error, 7.98. Row 11. x subscript n, 1.50. y subscript n, 3.1733. Actual Value, 3.4903. Absolute Error, 0.3171. Percentage Relative Error, 9.08.

In this case, with a step size h = 0.1, a 16% relative error in the calculation of the approximation to y(1.5) is totally unacceptable. At the expense of doubling the number of calculations, some improvement in accuracy is obtained by halving the step size to h = 0.05.

Errors in Numerical Methods

In choosing and using a numerical method for the solution of an initial-value problem, we must be aware of the various sources of errors. For some kinds of computation the accumulation of errors might reduce the accuracy of an approximation to the point of making the computation useless. On the other hand, depending on the use to which a numerical solution may be put, extreme accuracy may not be worth the added expense and complication.

One source of error always present in calculations is round-off error. This error results from the fact that any calculator or computer can represent numbers using only a finite number of digits. Suppose, for the sake of illustration, that we have a calculator that uses base 10 arithmetic and carries four digits, so that is represented in the calculator as 0.3333 and is represented as 0.1111. If we use this calculator to compute (x2)/(x) for x = 0.3334, we obtain

With the help of a little algebra, however, we see that

so that when x = 0.3334, (x2)/(x) ≈ 0.3334 + 0.3333 = 0.6667. This example shows that the effects of round-off error can be quite serious unless some care is taken. One way to reduce the effect of round-off error is to minimize the number of calculations. Another technique on a computer is to use double-precision arithmetic to check the results. In general, round-off error is unpredictable and difficult to analyze, and we will neglect it in the error analysis that follows. We will concentrate on investigating the error introduced by using a formula or algorithm to approximate the values of the solution.

Truncation Errors for Euler’s Method

In the sequence of values y1, y2, y3, . . . generated from (1), usually the value of y1 will not agree with the actual solution evaluated at x1, namely, y(x1), because the algorithm gives only a straight-line approximation to the solution. See Figure 2.6.2. The error is called the local truncation error, formula error, or discretization error. It occurs at each step; that is, if we assume that yn is accurate, then yn + 1 will contain a local truncation error.

To derive a formula for the local truncation error for Euler’s method, we use Taylor’s formula with remainder. If a function y(x) possesses k + 1 derivatives that are continuous on an open interval containing a and x, then

where c is some point between a and x. Setting k = 1, a = xn, and x = xn + 1 = xn + h, we get

.

Euler’s method (1) is the last formula without the last term; hence the local truncation error in yn + 1 is

where xn < c < xn + 1.

The value of c is usually unknown (it exists theoretically), and so the exact error cannot be calculated, but an upper bound on the absolute value of the error is

In discussing errors arising from the use of numerical methods, it is helpful to use the notation O(hn). To define this concept we let e(h) denote the error in a numerical calculation depending on h. Then e(h) is said to be of order hn, denoted by O(hn), if there is a constant C and a positive integer n such that |e(h)| ≤ Chn for h is sufficiently small. Thus the local truncation error for Euler’s method is O(h2). We note that, in general, if e(h) in a numerical method is of order hn, and h is halved, the new error is approximately C(h/2)n = Chn/2n; that is, the error is reduced by a factor of n.

EXAMPLE 1 Bound for Local Truncation Error

Find a bound for the local truncation errors for Euler’s method applied to y′ = 2xy, y(1) = 1.

SOLUTION

From the solution we get y″ = (2 + 4x2), and so the local truncation error is

where c is between xn and xn + h. In particular, for h = 0.1 we can get an upper bound on the local truncation error for y1 by replacing c by 1.1:

From Table 6.1.1 we see that the error after the first step is 0.0337, less than the value given by the bound.

Similarly, we can get a bound for the local truncation error for any of the five steps given in Table 6.1.1 by replacing c by 1.5 (this value of c gives the largest value of y″(c) for any of the steps and may be too generous for the first few steps). Doing this gives

(2)

as an upper bound for the local truncation error in each step.

Note in Example 1 that if h is halved to 0.05, then the error bound is 0.0480, about one-fourth as much as shown in (2). This is expected because the local truncation error for Euler’s method is O(h2).

In the above analysis we assumed that the value of yn was exact in the calculation of yn + 1, but it is not because it contains local truncation errors from previous steps. The total error in yn + 1 is an accumulation of the errors in each of the previous steps. This total error is called the global truncation error. A complete analysis of the global truncation error is beyond the scope of this text, but it can be shown that the global truncation error for Euler’s method is O(h).

We expect that, for Euler’s method, if the step size is halved the error will be approximately halved as well. This is borne out in Tables 6.1.1 and 6.1.2, where the absolute error at x = 1.50 with h = 0.1 is 0.5625 and with h = 0.05 is 0.3171, approximately half as large.

In general it can be shown that if a method for the numerical solution of a differential equation has local truncation error O(hα + 1), then the global truncation error is O(hα).

For the remainder of this section and in the subsequent sections we study methods that give significantly greater accuracy than Euler’s method.

Improved Euler’s Method

The numerical method defined by the formula

,(3)

where (4)

is commonly known as the improved Euler’s method. In order to compute yn+1 for n = 0, 1, 2, . . . , from (3) we must, at each step, first use Euler’s method (4) to obtain an initial estimate . For example, with n = 0, (4) would give = y0 + hf(x0, y0), and then knowing this value we use (3) to get y1 = y0 + h(f(x0, y0) + f(x1, ))/2, where x1 = x0 + h. These equations can be readily visualized. In FIGURE 6.1.1 observe that m0 = f(x0, y0) and m1 = f(x1, ) are slopes of the solid straight lines shown passing through the points (x0, y0) and (x1, ), respectively. By taking an average of these slopes, that is, mave = (f(x0, y0) + f(x1, ))/2, we obtain the slope of the parallel dashed skew lines. With the first step, rather than advancing along the line through (x0, y0) with slope f(x0, y0) to the point with y-coordinate obtained by Euler’s method, we advance instead along the red dashed line through (x0, y0) with slope mave until we reach x1. It seems plausible from inspection of the figure that y1 is an improvement over .

A curve, two solid lines, and two dashed lines are graphed on an x y plane. The curve labeled solution curve starts from a point in the second quadrant, goes down and to the right through the positive y axis, reaches a low point in the first quadrant. Then it goes up and to the right through the labeled points (x subscript 0, y subscript 0) and (x subscript 1, y(x subscript 1)), and ends at the top of the first quadrant. The first solid straight line is tangential to the curve and passes through the labeled points (x subscript 0, y subscript 0) and (x subscript 1, y subscript 1*). It is labeled: m subscript 0 equals f(x subscript 0, y subscript 0). The second solid straight line is parallel tangential to the curve and passes through the labeled point (x subscript 1, y subscript 1*). It is labeled: m subscript 1 equals f(x subscript 1, y subscript 1*). A red dashed line passes through the curve along the labeled points (x subscript 0, y subscript 0) and (x subscript 1, y subscript 1). It is labeled m subscript ave. A black dashed line parallel to the red dashed line passes through the labeled point (x subscript 1, y subscript 1*). It is labeled m subscript ave equals (f(x subscript 0, y subscript 0) + f(x subscript 1, y subscript 1*)) over 2. The values x subscript 0 and x subscript 1 are marked on the x axis. The distance between them is labeled h.

FIGURE 6.1.1 Slope mave is average of m0 and m1

In general, the improved Euler’s method is an example of a predictor–corrector method. The value of given by (4) predicts a value of y(xn), whereas the value of yn + 1 defined by formula (3) corrects this estimate.

EXAMPLE 2 Improved Euler’s Method

Use the improved Euler’s method to obtain the approximate value of y(1.5) for the solution of the initial-value problem y′ = 2xy, y(1) = 1. Compare the results for h = 0.1 and h = 0.05.

SOLUTION

With x0 = 1, y0 = 1, f(xn , yn) = 2xnyn, n = 0, and h = 0.1 we first compute (4):

= y0 + (0.1)(2x0 y0) = 1 + (0.1)2(1)(1) = 1.2.

We use this last value in (3) along with x1 = 1 + h = 1 + 0.1 = 1.1:

The comparative values of the calculations for h = 0.1 and h = 0.05 are given in Tables 6.1.3 and 6.1.4, respectively.

TABLE 6.1.3 Improved Euler’s Method with h = 0.1
The table captioned Improved Euler’s Method with h equals 0.1 has five columns and six rows. The column headings are as follows: Column 1, x subscript n. Column 2, y subscript n. Column 3, Actual Value. Column 4, Absolute Error. Column 5, Percentage Relative Error. The row entries are as follows: Row 1. x subscript n, 1.00. y subscript n, 1.0000. Actual Value, 1.0000. Absolute Error, 0.0000. Percentage Relative Error, 0.00. Row 2. x subscript n, 1.10. y subscript n, 1.2320. Actual Value, 1.2337. Absolute Error, 0.0017. Percentage Relative Error, 0.14. Row 3. x subscript n, 1.20. y subscript n, 1.5479. Actual Value, 1.5527. Absolute Error, 0.0048. Percentage Relative Error, 0.31. Row 4. x subscript n, 1.30. y subscript n, 1.9832. Actual Value, 1.9937. Absolute Error, 0.0106. Percentage Relative Error, 0.53. Row 5. x subscript n, 1.40. y subscript n, 2.5908. Actual Value, 2.6117. Absolute Error, 0.0209. Percentage Relative Error, 0.80. Row 6. x subscript n, 1.50. y subscript n, 3.4509. Actual Value, 3.4904. Absolute Error, 0.0394. Percentage Relative Error, 1.13.
TABLE 6.1.4 Improved Euler’s Method with h = 0.05
The table captioned Improved Euler’s Method with h equals 0.05 has five columns and eleven rows. The column headings are as follows: Column 1, x subscript n. Column 2, y subscript n. Column 3, Actual Value. Column 4, Absolute Error. Column 5, Percentage Relative Error. The row entries are as follows: Row 1. x subscript n, 1.00. y subscript n, 1.0000. Actual Value, 1.0000. Absolute Error, 0.0000. Percentage Relative Error, 0.00. Row 2. x subscript n, 1.05. y subscript n, 1.1077. Actual Value, 1.1079. Absolute Error, 0.0002. Percentage Relative Error, 0.02. Row 3. x subscript n, 1.10. y subscript n, 1.2332. Actual Value, 1.2337. Absolute Error, 0.0004. Percentage Relative Error, 0.04. Row 4. x subscript n, 1.15. y subscript n, 1.3798. Actual Value, 1.3806. Absolute Error, 0.0008. Percentage Relative Error, 0.06. Row 5. x subscript n, 1.20. y subscript n, 1.5514. Actual Value, 1.5527. Absolute Error, 0.0013. Percentage Relative Error, 0.08. Row 6. x subscript n, 1.25. y subscript n, 1.7531. Actual Value, 1.7551. Absolute Error, 0.0020. Percentage Relative Error, 0.11. Row 7. x subscript n, 1.30. y subscript n, 1.9909. Actual Value, 1.9937. Absolute Error, 0.0029. Percentage Relative Error, 0.14. Row 8. x subscript n, 1.35. y subscript n, 2.2721. Actual Value, 2.2762. Absolute Error, 0.0041. Percentage Relative Error, 0.18. Row 9. x subscript n, 1.40. y subscript n, 2.6060. Actual Value, 2.6117. Absolute Error, 0.0057. Percentage Relative Error, 0.22. Row 10. x subscript n, 1.45. y subscript n, 3.0038. Actual Value, 3.0117. Absolute Error, 0.0079. Percentage Relative Error, 0.26. Row 11. x subscript n, 1.50. y subscript n, 3.4795. Actual Value, 3.4904. Absolute Error, 0.0108. Percentage Relative Error, 0.31.

Note that we can’t compute all the first.

A brief word of caution is in order here. We cannot compute all the values of first and then substitute these values into formula (3). In other words, we cannot use the data in Table 6.1.1 to help construct the values in Table 6.1.3. Why not?

Truncation Errors for the Improved Euler’s Method

The local truncation error for the improved Euler’s method is O(h3). The derivation of this result is similar to the derivation of the local truncation error for Euler’s method. Since the local truncation error for the improved Euler’s method is O(h3), the global truncation error is O(h2). This can be seen in Example 2; when the step size is halved from h = 0.1 to h = 0.05, the absolute error at x = 1.50 is reduced from 0.0394 to 0.0108, a reduction of approximately ()2 = .

6.1 Exercises Answers to selected odd-numbered problems begin on page ANS-14.

Given the initial-value problems in Problems 1–10, use the improved Euler’s method to obtain a four-decimal approximation to the indicated value. First use h = 0.1 and then use h = 0.05.

  1. y′ = 2x − 3y + 1,     y(1) = 5; y(1.5)
  2. y′ = 4x − 2y,     y(0) = 2; y(0.5)
  3. y′ = 1 + y2,     y(0) = 0; y(0.5)
  4. y′ = x2 + y2,     y(0) = 1; y(0.5)
  5. y′ = e2y,     y(0) = 0; y(0.5)
  6. y′ = x + y2,     y(0) = 0; y(0.5)
  7. y′ = (x2 y)2,     y(0) = 0.5; y(0.5)
  8. y′ = xy + ,     y(0) = 1; y(0.5)
  9. y′ = xy2,     y(1) = 1; y(1.5)
  10. y′ = yy2,     y(0) = 0.5; y(0.5)
  11. Consider the initial-value problem y′ = (x + y − 1)2, y(0) = 2. Use the improved Euler’s method with h = 0.1 and h = 0.05 to obtain approximate values of the solution at x = 0.5. At each step compare the approximate value with the exact value of the analytic solution.
  12. Although it may not be obvious from the differential equation, its solution could “behave badly” near a point x at which we wish to approximate y(x). Numerical procedures may give widely differing results near this point. Let y(x) be the solution of the initial-value problem y′ = x2 + y3, y(1) = 1.
    1. Use a numerical solver to obtain the graph of the solution on the interval [1, 1.4].
    2. Using the step size h = 0.1, compare the results obtained from Euler’s method with the results from the improved Euler’s method in the approximation of y(1.4).
  13. Consider the initial-value problem y′ = 2y, y(0) = 1. The analytic solution is y = e2x.
    1. Approximate y(0.1) using one step and Euler’s method.
    2. Find a bound for the local truncation error in y1.
    3. Compare the actual error in y1 with your error bound.
    4. Approximate y(0.1) using two steps and Euler’s method.
    5. Verify that the global truncation error for Euler’s method is O(h) by comparing the errors in parts (a) and (d).
  14. Repeat Problem 13 using the improved Euler’s method. Its global truncation error is O(h2).
  15. Repeat Problem 13 using the initial-value problem y′ = x − 2y, y(0) = 1. The analytic solution is

    y = x + e−2x.

  16. Repeat Problem 15 using the improved Euler’s method. Its global truncation error is O(h2).
  17. Consider the initial-value problem y′ = 2x − 3y + 1, y(1) = 5. The analytic solution is

    y(x) = + x + e−3(x − 1).

    1. Find a formula involving c and h for the local truncation error in the nth step if Euler’s method is used.
    2. Find a bound for the local truncation error in each step if h = 0.1 is used to approximate y(1.5).
    3. Approximate y(1.5) using h = 0.1 and h = 0.05 with Euler’s method. See Problem 1 in Exercises 2.6.
    4. Calculate the errors in part (c) and verify that the global truncation error of Euler’s method is O(h).
  18. Repeat Problem 17 using the improved Euler’s method, which has a global truncation error O(h2). See Problem 1. You may need to keep more than four decimal places to see the effect of reducing the order of error.
  19. Repeat Problem 17 for the initial-value problem y′ = ey, y(0) = 0. The analytic solution is y(x) = ln(x + 1). Approximate y(0.5). See Problem 5 in Exercises 2.6.
  20. Repeat Problem 19 using the improved Euler’s method, which has a global truncation error O(h2). See Problem 5. You may need to keep more than four decimal places to see the effect of reducing the order of error.

Discussion Problem

  1. Answer the question: “Why not?” that follows the three sentences after Example 2 on page 310.