Back to the on-screen lesson ·

Heun's method

A trial step taken only to sample the slope at the far end, and the average of the two slopes that buys a whole order over Euler.

Paper packet. Every task here also exists on screen, where it is checked automatically; answers written on paper are not assessed by Nydus. When you are back at a device, enter your answers there.

1. What you will learn

By the end of this lesson you will be able to carry out a Heun step stage by stage, explain why averaging the two slopes raises the order, and compare Heun with Euler at equal cost rather than at equal step count.

2. What you already know

You know that Euler's method commits to the slope at the start of a step, and that this is why it lags a solution which curves upwards. You also know, from quadrature, that averaging the two ends of an interval is worth an order over taking one end.

3. The words this lesson uses

A predictor is a provisional value used only so that something can be evaluated at it; a corrector is the step actually taken. A stage is one slope evaluation inside a step. Heun's method is the simplest two-stage Runge-Kutta method, and is also called the improved Euler method or the explicit trapezoidal method.

4. Heun's method

Euler's weakness is that it uses the slope at one end of the step as though it held across the whole step. Heun fixes it in the obvious way, and the fix is worth an order. Predict: $\tilde{y} = y_n + hf(t_n, y_n)$, a full Euler step, used only to find out where the far end roughly is. Correct: evaluate the slope there, $k_2 = f(t_n + h, \tilde{y})$, and take the real step from the original point with the average of the two slopes, $y_{n+1} = y_n + \tfrac{h}{2}(k_1 + k_2)$. The predicted value is then thrown away. Applied to $y' = f(t)$ alone, the method is the trapezoid rule, which is exactly why the order goes up: the local error becomes $O(h^{3})$ and the global error $O(h^{2})$, so halving the step now divides the final error by four. The cost is two slope evaluations per step, and the comparison that matters is at equal evaluations, not equal steps — where Heun still wins by a factor that grows with the budget. What it does not buy is stability: its stability region is a little larger than Euler's and still bounded, and a step outside it fails in the same way.

Another way: picture

Euler walks along the arrow it is standing on. Heun walks along that arrow to see what the arrow looks like over there, walks back, and then sets off again in the average of the two directions. On a curving solution the two arrows straddle the truth, and their average is much closer to it than either.

Another way: steps

  1. $k_1 = f(t_n, y_n)$.
  2. $\tilde{y} = y_n + hk_1$.
  3. $k_2 = f(t_n + h, \tilde{y})$.
  4. $y_{n+1} = y_n + \tfrac{h}{2}(k_1 + k_2)$, and discard $\tilde{y}$.

5. The mistake to watch for

The predicted value is not a half-answer to be blended with the corrected one, and it is not where the step goes. It exists for one purpose — to give the slope somewhere to be evaluated — and is discarded immediately. Code that carries it forward is taking two Euler steps of size $h$ and will be first order and twice as expensive, which is the worst of both methods and is easy to write by accident.

6. Heun against Euler on the same problem

  1. $y' = y$, $y(0) = 1$, $h = \tfrac12$: $k_1 = 1$, trial $1.5$, $k_2 = 1.5$.

    Average slope $1.25$.

  2. So $y_1 = 1 + \tfrac12 \times 1.25 = 1.625$, against Euler's $1.5$ and the true $e^{1/2} \approx 1.6487$.

    The error has fallen by about four.

  3. $1 + z + \tfrac{z^{2}}{2}$ is three terms of the exponential series where Euler had two.

    One more term, one more order.

7. Heun as the trapezoid rule

  1. When $f$ depends on $t$ only, the prediction does not affect $k_2$ at all.

    $k_2 = f(t_n + h)$ exactly.

  2. So the step is $y_n + \tfrac{h}{2}(f(t_n) + f(t_n + h))$.

    The trapezoid rule, exactly.

  3. And its second-order accuracy is the composite trapezoid rule's, met again in a different subject.

    One idea, two names.

8. Your turn: one Heun step on $y' = 2y$ from $y(0) = 1$ with $h = \tfrac12$

  1. $k_1 = 2$, so the trial value is $1 + \tfrac12 \times 2 = 2$.

  2. $k_2 = 2 \times 2 = 4$, and the average slope is $3$.

  3. Your turn: work this step out. Its working is at the end of the packet.

    So $y_1 = 1 + \tfrac12 \times 3 = 2.5$, against Euler's $2$ and the true $e \approx 2.718$.

9. Guided practice

Take one step of Heun's method on $y' = 2y$ from $y(0) = 1$ with step $\tfrac12$. Fill in the two slopes, the trial value, and the result.

Value
Slope where you stand
Trial value after a full step
Slope at the trial value
Value after the real step

10. Guided practice

Heun's method costs two slope evaluations a step where Euler's costs one. What does the second evaluation buy?

11. Practice

Put one step of Heun's method, inside a loop of $39$ steps, into order.

Number the steps in order (write the number in the box):

12. Practice

A Heun step on $y' = 2y$ involves four quantities. Match each to its job.

The only information available at the start, and all Euler would useA guess at the far end, formed only so the slope can be sampled thereAn estimate of the slope at the far end, not the true oneThe slope the real step is taken with, from the original point
The first slope
The trial value
The second slope
The average of the two slopes

13. Somewhere new

Over an interval of length $1$ you can afford $12$ slope evaluations. Euler then uses a step of $\tfrac{1}{12}$ and Heun, at two evaluations a step, uses $\tfrac{2}{12}$. Euler's global error is proportional to its step and Heun's to the square of its step, with the same constant. What is the ratio of Heun's error to Euler's? Give a fraction.

Answer:

14. Lesson test

Lesson test: one question per skill, one attempt each, no hints. Your answers are checked when you submit.

15. Test question

Take one Heun step on $y' = 2y$ from $y(0) = 4$ with step $\tfrac12$. What is the value after the step?

Answer:

16. What you can do now

You can run a Heun step and say what each of its four quantities is for. Say in your own words why the predicted value is discarded rather than reported.

Working for the steps left to you

8. Your turn: one Heun step on $y' = 2y$ from $y(0) = 1$ with $h = \tfrac12$, step 3