4.8.23 · D2Numerical Methods

Visual walkthrough — Modified Euler (Heun's method)

1,848 words8 min readBack to topic

A picture-by-picture build of the corrector formula, starting from "what does a slope even do to a curve?" — every symbol earned before it appears.

We are solving one thing: a curve whose steepness at any point is dictated by a rule. That rule is written . Let us unpack that before anything else.


Step 1 — A slope is a direction to walk

WHAT. At the start point the machine gives us a number . That number is a slope: it tells us which way to point our feet.

WHY. A slope of means "for every step right, go up ." So if we step forward a distance , altitude changes by . This is the only honest thing we know at the very first instant.

PICTURE. The green curve is the true answer we cannot see yet. At the start we can only feel the slope under our feet — the yellow arrow. Extending that arrow is a straight guess.

Figure — Modified Euler (Heun's method)

Each symbol: eats the pair and returns the steepness there. Nothing more.


Step 2 — Plain Euler: commit to the start-slope (and drift)

WHAT. Walk the whole step using only :

WHY. It is the cheapest possible move — we already have , so just follow it. The superscript marks this as a predictor (a rough draft, not the final answer).

PICTURE. The yellow straight line follows the start-slope perfectly. But the green true curve bends away — its slope keeps changing. So Euler lands at the yellow dot, and the true endpoint is the green dot. The vertical red gap is the error.

Figure — Modified Euler (Heun's method)


Step 3 — Peek at the slope where Euler thinks we land

WHAT. Feed the machine the predicted endpoint to get a second slope:

WHY. We wanted to know how steep the trail is at the end of the step — but we cannot ask the machine about the end until we guess the end's altitude. Step 2's draft is exactly that guess. So is our best estimate of the exit-slope.

PICTURE. The blue arrow sits at the yellow (predicted) endpoint and shows the exit-slope . Notice it points differently from — steeper or shallower depending on the curve.

Figure — Modified Euler (Heun's method)


Step 4 — Why average the two slopes? (the trapezoid idea)

WHAT. We now hold two slopes: at the start, at the end. Heun walks using their average:

WHY. Go back to the exact truth. The change in altitude over the step is the area under the slope-curve from to : That integral sign just means "add up all the little slope-contributions across the step." We cannot compute it exactly (we don't know inside), so we approximate the region under the slope-curve by a trapezoid: a shape with the true start-height on the left, the estimated end-height on the right, joined by a straight top.

PICTURE. Left: the true slope varies (green). Right: we replace it by a trapezoid whose left edge is , right edge is . The trapezoid's area is its width times its average height .

Figure — Modified Euler (Heun's method)

This is exactly the Trapezoidal Rule in disguise. A trapezoid hugs a gently-curving graph far better than the single rectangle Euler used — that is the entire reason Heun beats Euler.


Step 5 — Assemble the corrector

WHAT. Add the trapezoid area to the start altitude:

WHY. The integral is the altitude change; the trapezoid is our estimate of it; adding it to lands us at the corrected endpoint. We call this the corrector because it repairs the crude predictor of Step 2.

PICTURE. Three straight moves overlaid: yellow (Euler, follows ), blue (exit-slope ), and the red average line whose slope is . The red endpoint sits almost exactly on the green true curve — the drift is nearly gone.

Figure — Modified Euler (Heun's method)


Step 6 — Edge case: flat start ()

WHAT. Consider , , . Here .

WHY it matters. With the predictor does not move: . Plain Euler would stop here forever and report — it never notices the curve is about to bend down. This is the degenerate case where Euler is blindest.

PICTURE. The start-arrow (yellow) is perfectly horizontal. But peeking ahead, — a real downward slope (blue). Averaging and gives , and Heun descends. The peek rescues the flat-start disaster.

Figure — Modified Euler (Heun's method)

Exact: . Heun's error ; Euler stuck at with error — about worse. See Order of Accuracy and Step Size.


Step 7 — Optional refinement: iterate the corrector

WHAT. The corrected is a better altitude than the predictor. So we can re-peek: recompute using instead of , then correct again.

WHY. The trapezoidal equation is implicit — the true appears on both sides. One correction is a fixed step toward the solution; iterating drives it closer. For , , : first corrector gives , re-peek , correct again . The exact answer is .

PICTURE. The red endpoint nudges once more toward the green curve — a small final polish. This links Heun to the wider family of Predictor-Corrector Methods.

Figure — Modified Euler (Heun's method)

The one-picture summary

Everything at once: start slope (yellow), peeked end slope (blue), the averaged red walk landing on the green truth, with the trapezoid (Step 4) shaded underneath to remind us where the average came from.

Figure — Modified Euler (Heun's method)
Recall Feynman: retell the whole walkthrough in plain words

You are hiking a curving trail. Step 1: feel the slope under your feet — that is . Step 2: naively walk straight in that direction for a while; but the trail curved, so you drifted off — that is plain Euler's error. Step 3: instead of committing, take a practice step to where you'd land, and feel the slope there — that is . Step 4: the true climb over the interval is the area under the changing-slope graph; a trapezoid (flat top from to ) estimates that area, and a trapezoid's area is width times the average of its two heights. Step 5: so walk using the average of the start-slope and the peeked end-slope, times the step — and you land almost exactly on the real trail. Step 6: even when the start is dead flat and Euler would freeze, the peek ahead spots the coming descent. Step 7: if you want to be fussy, re-peek from your improved landing spot and nudge once more.

Active Recall

Why does Heun average two slopes instead of using one?
Because the true altitude change is the area under the slope-curve, and a trapezoid (average of end heights) approximates that area far better than one rectangle.
What geometric shape gives the formula?
A trapezoid — width times average height .
In the flat-start case , what saves Heun when Euler freezes?
The peeked end-slope still detects the curve bending, so the average is nonzero.

Connections

  • Modified Euler (Heun's method) — the parent this page unpacks.
  • Euler's Method — Steps 1–2 are exactly plain Euler (the predictor).
  • Trapezoidal Rule — Step 4 is this rule applied to the slope integral.
  • Runge-Kutta Methods — the assembled formula is RK2.
  • Order of Accuracy and Step Size — why the trapezoid buys .
  • Predictor-Corrector Methods — Step 7 iterates the corrector.
  • Taylor Series Methods — proves the second-order match.