8.5 Numerical Methods II: The Improved Euler Method
Euler's method from Section 8.4 is easy to understand and easy to program, but it is slow to converge: halving the step size only halves the error. To get three more correct digits you need a thousand times more steps. In this section we make one small, clever change to Euler's method and obtain a method whose error drops by a factor of four each time the step is halved. The price is one extra evaluation of the slope function per step, which is almost always worth paying.
Throughout, we work with the initial-value problem
on equally spaced points . Section 8.4 called the exact solution ; from here on, to keep formulas short, we write it simply as . So is the exact value and is our approximation of it.
Where Euler's method loses accuracy
Start from the exact relation between two neighbouring values of the solution. Integrating from to gives
This formula is exact. Every one-step method is simply a way to estimate the integral on the right.
Euler's method replaces the integrand by its value at the left end of the interval. Geometrically, it approximates the area under the curve by a rectangle of height . If the slope of the solution changes across the step (and it almost always does), the rectangle misses a whole sliver of area. That sliver is the source of the local error you met in Section 8.4.
From calculus we know a better estimate of an integral: the trapezoid rule, which averages the integrand at both ends,
Applied to our integral, it suggests
There is a catch. The unknown appears on both sides, buried inside . For a nonlinear we cannot simply solve for it. A formula of this kind is called implicit.
Predict, then correct
The way out is wonderfully simple. We need only to evaluate the slope at the right end of the interval, and for that purpose a rough value is good enough. So we first predict with an ordinary Euler step, and then use this prediction inside the trapezoid formula to correct it.
Given at , compute
Methods built from a rough explicit guess followed by an improving formula are called predictor–corrector methods. Heun's method is the simplest of them.
Figure 8.5.1 shows one step. The Euler line (slope ) undershoots the curve, because the solution bends upward. At the predicted point we sample the slope again and get , which is too steep for the beginning of the step but about right for its end. Their average is a much better description of the whole step.
- Evaluate the slope at the current point: .
- Take a trial Euler step: .
- Evaluate the slope at the trial point: .
- Step with the average slope: . Discard .
- Repeat from the new point .
The predicted value is only scaffolding. The next step starts from the corrected value , never from . Also note that uses the new abscissa , not .
Worked examples
We will use the following problem as a running test case in this section and the next two:
It is linear, so Chapter 2 gives its exact solution. With the integrating factor one finds , and forces :
Knowing the exact answer lets us measure the true error of every method. In all tables we carry full precision in the calculation (errors included) and round only the displayed numbers to six decimals, so a last digit may occasionally differ by one from what you get by subtracting two rounded entries.
Use Heun's method with to approximate the solution of , , at . Compare with Euler's method and with the exact solution.
Solution
- First step (). Here , , . The exact value is , so the error is .
- Second step (). Now , , .
- Remaining steps. Continuing in the same way gives the table below.
0.0 1.000000 1.000000 1.200000 1.160000 1.216000 0.2 1.216000 1.176000 1.451200 1.291200 1.462720 0.4 1.462720 1.302720 1.723264 1.363264 1.729318 0.6 1.729318 1.369318 2.003182 1.363182 2.002568 0.8 2.002568 1.362568 2.275082 1.275082 2.266334 - Comparison. Euler's method with the same gives .
At , Heun's error is about times smaller than Euler's, although each Heun step costs only two slope evaluations instead of one.exact Euler Euler error Heun Heun error 0.2 1.218597 1.200000 0.018597 1.216000 0.002597 0.4 1.468175 1.432000 0.036175 1.462720 0.005455 0.6 1.737881 1.686400 0.051481 1.729318 0.008563 0.8 2.014459 1.951680 0.062779 2.002568 0.011891 1.0 2.281718 2.214016 0.067702 2.266334 0.015385
Try it yourself. The solver below reproduces the table of Example 8.5.1 with every intermediate quantity. Change to and watch the error at fall by about a factor of four; then type your own , for instance 1 + y^2 with exact solution tan(x).
How accurate is Heun's method?
A single table does not tell us how the error behaves as . For that we compare the method with the Taylor expansion of the exact solution, exactly as Section 8.4 did for Euler's method.
The exact solution over one step
Suppose we start a step from the exact value, . Taylor's theorem gives
We know . To find , differentiate with the chain rule (write , for the partial derivatives):
So, with every function evaluated at ,
Heun's step over the same interval
Now expand , where . Taylor's theorem in two variables, with increments in and in , gives
Insert this into the corrector:
Compare (A) and (B): they agree in the terms of order , and . They first differ at order . Euler's method, , already disagrees with (A) at order .
Suppose and its partial derivatives up to second order are continuous near the solution curve, and that the solution has a continuous third derivative on . Then Heun's method has local truncation error , and its global error at any fixed in satisfies
for some constant that does not depend on . In short, Heun's method is a second-order method.
The step from "local " to "global " uses the same reasoning as for Euler's method in Section 8.4. To reach a fixed point we take steps; each adds a local error of size about ; and, under the stated smoothness, earlier errors are not amplified by more than a bounded factor. The total is roughly , which is of order .
If the error is about , then halving divides it by , and dividing by divides it by . For Euler's method (first order) the same changes divide the error only by and by .
Solve , by Euler's method and by Heun's method with . Tabulate the error at and check the predicted orders.
Solution
- Errors. The exact value is . Running both methods to (that is, steps) gives:
The "ratio" column is the previous error divided by the current one.Euler error ratio Heun error ratio 0.2 0.067702 – 0.015385 – 0.1 0.034835 1.94 0.003961 3.88 0.05 0.017681 1.97 0.001003 3.95 0.025 0.008909 1.98 0.000252 3.98 - Reading the ratios. For Euler the ratios approach ; for Heun they approach . This is exactly the behaviour predicted for first- and second-order methods.
- Estimating the order. If error , then the ratio for halving is , so . For the last Heun ratio, .
A log–log plot makes this visible at a glance. If the error is , then , a straight line of slope .
Water drains from a cylindrical tank through a hole in its bottom. By Torricelli's law the water depth (in metres) obeys , with in minutes. The initial depth is . Use Heun's method with to estimate and , and compare with the exact solution.
Solution
- Exact solution. The equation is separable (Section 2.2): With we get , so and for (the tank is empty at min).
- First step. , , . Exact: . Error: .
- Second step. Exact: . Error: , less than of the depth, even with a step of half a minute. (Euler's method with the same step, Example 8.4.3, was off by here.)
A special case: pure integration
When depends on only, the differential equation is just an integration problem: . In that case does not depend on the predictor at all, and Heun's step becomes
which is exactly the trapezoid rule of calculus. So Heun's method is the natural generalisation of the trapezoid rule to equations whose slope depends on .
The function has no elementary antiderivative, yet its integral appears constantly in heat conduction and probability. Use Heun's method with on , to estimate .
Solution
- Slopes needed. Since at one step equals at the next, we need only at the five nodes:
- Four Heun steps.
- Check. The true value is . The error, , is the familiar error of the trapezoid rule with four panels.
One could feed the corrected value back into and correct again, repeating until the numbers stop changing. The limit is the solution of the implicit trapezoid formula from the start of this section. This does not raise the order: the trapezoid rule itself is second order, so the iterations only shrink the constant a little, at the cost of extra slope evaluations. To gain real accuracy it is better to sample the slope at new places inside the step. That is the idea behind the Runge–Kutta methods of Section 8.6.
Summary
- Heun's method estimates with the trapezoid rule, using an Euler predictor to supply the unknown right-end value.
- It costs two evaluations of per step and is second order: global error , local error .
- Halving divides the error by about , a fact you can use to check a computation.
- For it reduces to the trapezoid rule.
Exercises
- Use Heun's method with to approximate and for , . Compare with the exact solution .
Answer
, ; exact and (errors , ). - Use Heun's method with to approximate the solution of , , at . The exact solution is .
Answer
, , ; exact , , . - Use Heun's method with to approximate for , (this equation has no elementary solution).
Answer
, . (A very accurate computation gives .) - Apply one Heun step to the test equation ( a constant). Show that , and compare the multiplier with the exact factor .
Answer
, , so . The multiplier matches up to the term; the first difference is , a local error of order . - The midpoint method uses . (a) Take one step with for , . (b) Using the Taylor expansion from this section, show that the midpoint method is also second order.
Answer
(a) (exact ). (b) , so , which matches (A). - For the first step of Example 8.5.1, iterate the corrector: start from and repeat . Find the first three iterates and the limit. Is the limit closer to than Heun's value ?
Answer
, , ; the limit solves , so . Yes, a little closer (error instead of ), but the order is unchanged. - A second-order method gives an error of at some point when . Estimate the error with and with . If a computation instead gives errors and for and , what order does this suggest?
Answer
About and . The ratio gives , i.e. order 2. - Use Heun's method with on , , to estimate . Which classical rule have you used, and what is the error?
Answer
The trapezoid rule: . Exact ; error . - For , , Example 8.5.2 shows Heun's error at is about . Roughly what step size makes the error smaller than ? How many slope evaluations is that, and how many would Euler's method need (its error is about )?
Answer
; e.g. (80 steps, 160 evaluations; actual error ). Euler needs , about steps and evaluations. - Use Heun's method with for the tank of Example 8.5.3 to estimate , continuing from .
Answer
, , , ; exact (error ).