Exercises — Modified Euler (Heun's method)
Ten graded problems, from "just spot the pieces" up to "invent a variation." Every one has a full worked solution hidden inside a collapsible box — try first, then reveal.
This page assumes the machinery from the parent note: Heun's method. Recall the two moves we lean on constantly:
Throughout, = slope at the start, = slope at the predicted end. Every problem is just: find , take a peek-step, find , average. Keep that picture in front of you.
The figure below is the mental image to hold for every problem on this page — it draws all four objects we juggle (start slope, predicted endpoint, end slope, averaged Heun step) for the running example (drawn with a big so the geometry is visible):

Read it like this: the coral dashed line is the start slope — follow it alone and you land at the coral predicted point (that is exactly the plain-Euler guess in every predictor step below, e.g. L1.1's or L2.1's ). The butter dotted line is the end slope read at that predicted point. The lavender line is the Heun step: its slope is the average of coral and butter, and it lands at the lavender , which sits far closer to the mint true point than the coral prediction did. Whenever a solution below says "average the two slopes," picture the lavender line splitting the angle between the coral and butter lines.
Level 1 — Recognition
(Can you point at the pieces and plug numbers into the machine?)
L1.1
Given with and . This does not depend on . Compute , the predictor , then , and finally .
Recall Solution
What we do first: read off the start point. , .
— slope at the start (the coral dashed line in the figure). Plug into : .
Predictor — the peek step (walk along coral to the predicted point). . Why? We need a value of at the endpoint so we can evaluate the end-slope.
— slope at the predicted end (the butter dotted line). . Since ignores here, .
Corrector — average and step (the lavender line). Sanity note: because has no , Heun here is exactly the trapezoidal rule on , so is exact. No error at all.
L1.2
For , , , identify and (numbers), then give .
Recall Solution
: . Predictor: . : . Corrector: Exact: . Error — tiny.
Level 2 — Application
(Run the full method on a real ODE, one and then two steps.)
L2.1
Solve , , one Heun step to reach with .
Recall Solution
, , , .
: . Predictor: . : . Corrector: Exact solution gives . Error .
L2.2
Same ODE , , but take two steps of to reach . Compare with the single-step answer above.
Recall Solution
Step 1 (from to ): ; predictor ; ;
Step 2 (from , to ): ; predictor ; ;
Compare: two-step vs single-step ; exact . Errors: single-step , two-step . Halving cut the error by about — exactly the promise.
Level 3 — Analysis
(Reason about the method itself, not just crank numbers.)
L3.1
For the linear ODE , show that one Heun step is i.e. Heun reproduces the exponential up to and including the term.
Recall Solution
, so the value of is irrelevant.
: . Predictor: . : . Corrector:
= y_0 + \frac{h\lambda}{2}\big[1 + 1 + h\lambda\big]y_0.$$ $$y_1 = y_0\Big[1 + \frac{h\lambda}{2}(2 + h\lambda)\Big] = y_0\Big[1 + h\lambda + \tfrac{1}{2}(h\lambda)^2\Big].$$ **What this means:** the true step is $y_1 = e^{h\lambda}y_0 = y_0(1 + h\lambda + \tfrac{1}{2}(h\lambda)^2 + \tfrac{1}{6}(h\lambda)^3 + \dots)$. Heun matches the first **three** terms and first disagrees at $(h\lambda)^3$ — exactly the fingerprint of a second-order method. This is the linear-case proof behind [[Order of Accuracy and Step Size]].L3.2
Take with (a fast-decaying, "stiff" problem), . Using the amplification factor from L3.1, decide whether Heun stays bounded (does not blow up) for and for .
Recall Solution
Each step multiplies by where . The numerical solution stays bounded iff .
: . . Since , stable — values shrink, matching the true decaying solution.
: . . Since , unstable — each step grows the value by , even though the true solution is racing to zero.
The full picture (complex ). In general can be complex (oscillatory or spiral solutions), so is a point in the complex plane. The region of absolute stability of RK2 is the set of complex with — a bounded egg-shaped region hugging the origin in the left half-plane. Our real cases are just the slice along the negative real axis: it turns out there exactly for , so sits inside (stable) and falls outside (unstable). For a stiff problem you must keep inside that region.
What this teaches: accuracy order is not the whole story. For stiff problems the step must be small enough to keep in the stability region, or the answer oscillates and explodes.
Level 4 — Synthesis
(Combine ideas — iterated correctors, weighted variants, error estimation.)
L4.1 (Iterated corrector)
For , , : do the predictor + corrector, then iterate the corrector twice more (re-feeding the latest into each time). Report the sequence and where it settles.
Recall Solution
(fixed — it only uses the start point).
The implicit equation we are solving. The true trapezoidal corrector is implicit because the unknown appears on both sides:
= 1 + 0.05\big[1 + (0.1 + y_1)\big] = 1.055 + 0.05\,y_1.$$ We solve it by **fixed-point iteration**: write $y_1^{(n+1)} = 1.055 + 0.05\,y_1^{(n)}$ and feed each output back in. **Iteration 0 (predictor):** $y^{(0)} = 1 + 0.1(1) = 1.1$. **Iteration 1:** $k_2 = f(0.1, 1.1) = 1.2$; $\;y^{(1)} = 1 + 0.05(1 + 1.2) = 1.11$. **Iteration 2:** $k_2 = f(0.1, 1.11) = 1.21$; $\;y^{(2)} = 1 + 0.05(1 + 1.21) = 1.1105$. **Iteration 3:** $k_2 = f(0.1, 1.1105) = 1.2105$; $\;y^{(3)} = 1 + 0.05(1 + 1.2105) = 1.110525$. **Where it settles.** Because the map has slope $0.05$ (well below $1$), the iteration is a contraction and converges to the exact fixed point $y_1^{*} = \dfrac{1.055}{1-0.05} = \dfrac{1.055}{0.95} = 1.1105263\ldots$ — the true solution of the implicit trapezoidal equation. The iterates $1.1,\,1.11,\,1.1105,\,1.110525,\dots$ march straight to it. **What we learn:** iterating solves the implicit corrector more exactly, but it converges to the trapezoid's own answer, which still carries the method's $O(h^2)$ truncation error against the ODE's exact $y = 2e^{0.1}-1.1 = 1.110342$ — iterating cannot beat the underlying rule. This is the heart of [[Predictor-Corrector Methods]].L4.2 (Error estimate from predictor vs corrector)
A cheap error indicator per step is the gap . Compute it for , , , and comment.
Recall Solution
From L4.1: predictor , first corrector . The actual global error at this point (against exact ) is . The predictor–corrector gap () is larger than the true error but tracks the same order in — it is proportional to and is used in adaptive step-size control to decide whether to shrink or grow . It's a conservative alarm, not the exact error.
Level 5 — Mastery
(Prove/derive a general result, or build a new variant.)
L5.1 (Order-2 condition for a general two-slope method)
Consider a general two-stage scheme
y_1 = y_0 + h(a\,k_1 + b\,k_2).$$ Show that Heun ($p=1,\,a=b=\tfrac12$) satisfies the two conditions needed for **second order**, and find *another* choice of $(p,a,b)$ that is also second order. > [!recall]- Solution > **Notation first.** Let $f_x := \dfrac{\partial f}{\partial x}$ and $f_y := \dfrac{\partial f}{\partial y}$, > both **evaluated at the start point** $(x_0,y_0)$, and write $f := f(x_0,y_0)$. These measure how > fast $f$ changes as you nudge $x$ (holding $y$) or nudge $y$ (holding $x$). > > **Why a two-variable Taylor expansion?** The true step's Taylor series involves $y'' $, and by > the chain rule $y'' = \dfrac{d}{dx}f(x,y(x)) = f_x + f_y\,y' = f_x + f_y f$. So to compare the > scheme with the truth at order $h^2$ we must expand $f$ at a *shifted* point $(x_0+ph,\,y_0+ph\,k_1)$. > The multivariable first-order Taylor expansion is > $$f(x_0+\Delta x,\ y_0+\Delta y) = f + f_x\,\Delta x + f_y\,\Delta y + O(\Delta^2),$$ > i.e. "value plus (rate in $x$)$\times$(step in $x$) plus (rate in $y$)$\times$(step in $y$)." > > **Apply it to $k_2$.** Here $\Delta x = ph$ and $\Delta y = ph\,k_1 = ph\,f$, so > $$k_2 = f + f_x(ph) + f_y(ph\,f) + O(h^2) = f + ph\,f_x + ph\,f\,f_y + O(h^2).$$ > > **Build the scheme's step and match Taylor.** True step: > $$y(x_1) = y_0 + h f + \tfrac{h^2}{2}(f_x + f_y f) + O(h^3).$$ > Scheme: > $$y_1 = y_0 + h\big(a f + b[f + ph f_x + ph f f_y]\big) + O(h^3) > = y_0 + (a+b)hf + bph^2(f_x + f f_y) + O(h^3).$$ > > **Match term by term:** > - $h^1$ term: $(a+b) = 1.$ > - $h^2$ term: $bp = \tfrac12.$ > > These are the **two order-2 conditions**. Heun uses $p=1,\ b=\tfrac12$: check $a+b = \tfrac12+\tfrac12 = 1$ ✓ and $bp = \tfrac12\cdot1 = \tfrac12$ ✓. > > **Another valid choice — the midpoint method.** Take $p=\tfrac12$. Then $bp=\tfrac12$ forces > $b = 1$, and $a+b=1$ forces $a = 0$: > $$k_1 = f(x_0,y_0),\quad k_2 = f\big(x_0+\tfrac{h}{2},\,y_0+\tfrac{h}{2}k_1\big),\quad y_1 = y_0 + h\,k_2.$$ > This is the **midpoint (modified Euler-midpoint) method** — also second order, using only the > single mid-step slope. Both live inside the RK2 family (see [[Runge-Kutta Methods]]). ### L5.2 (Apply the midpoint variant) Use the midpoint method from L5.1 on $y' = x+y$, $y(0)=1$, $h=0.1$, and compare its error to Heun's ($1.11$). > [!recall]- Solution > $k_1 = f(0,1) = 1$. > Mid-point value: $x_0 + \tfrac{h}{2} = 0.05$, $\;y_0 + \tfrac{h}{2}k_1 = 1 + 0.05 = 1.05$. > $k_2 = f(0.05, 1.05) = 0.05 + 1.05 = 1.1$. > $$y_1 = 1 + 0.1(1.1) = \mathbf{1.11}.$$ > Exact $= 1.110342$; error $\approx 0.00034$ — essentially the same accuracy as Heun's, as both > are order 2. They differ only in the third-order term, so for this smooth problem they land at > the same rounded value. > [!mistake] L5 trap: thinking there is only ONE second-order method > **Why it feels right:** Heun is the one everybody names, so it feels canonical/unique. > **Why it's wrong:** the order-2 conditions $a+b=1$, $bp=\tfrac12$ have a **one-parameter > family** of solutions (pick any $p\neq0$). Heun ($p=1$), midpoint ($p=\tfrac12$), and Ralston's > method ($p=\tfrac23$) are all second order. > **Fix:** "second order" is a property (matching Taylor to $h^2$), satisfied by infinitely many > two-stage schemes — Heun is just the equal-weight member. --- ## Connections - [[Euler's Method]] — every predictor here is one Euler step. - [[Trapezoidal Rule]] — the corrector; L1.1 is exactly this rule. - [[Runge-Kutta Methods]] — L5.1's family is RK2; midpoint and Ralston live there too. - [[Order of Accuracy and Step Size]] — L2.2 and L3.1 demonstrate the $O(h^2)$ scaling. - [[Predictor-Corrector Methods]] — L4.1's iteration is the prototype. - [[Taylor Series Methods]] — L5.1 matches the Taylor expansion term by term.