4.8.25 · D4Numerical Methods

Exercises — Adaptive step-size — RK45, error control

3,069 words14 min readBack to topic

The one formula this whole page turns on:

Before you touch a single exercise, let us pin down every symbol so nothing is used before it is defined.

Read the figure below before starting. It plots, for a step that lands exactly at tol, the predicted next-step error as a fraction of tol against the choice of — showing why is the safe-but-not-wasteful sweet spot, and marking the accept region.

Figure — Adaptive step-size — RK45, error control

See the parent note for the fuller stage-by-stage derivation.


Level 1 — Recognition

Recall Solution L1.1

(a) An embedded Runge–Kutta pair (RK45 / Fehlberg / Dormand–Prince). (b) . For a system this is the tolerance-scaled RMS norm (accept when ); for a single equation it is just . It is free because it reuses every expensive -evaluation and adds only a cheap weighted difference . (c) The controller uses : the error estimate essentially measures the 4th-order result's local error. You still advance with (local extrapolation), but the exponent in the update is using . See Order of a Numerical Method.

Recall Solution L1.2

Rule: accept iff .

  • A: accept.
  • B: accept (equality passes).
  • C: reject, redo the step from the same .

Level 2 — Application

Recall Solution L2.1

(a) accept. (b) Ratio . We had error to spare, so we grow — but only by , not by 20, because local error scales like .

Recall Solution L2.2

(a) reject. (b) Ratio . Retry from the same with .

Recall Solution L2.3

(a) . (b) accept (the relative part saved us). (c) Ratio . Note how using only atol () would have rejected this perfectly good step — see Local vs Global Truncation Error for why absolute-only tolerances misbehave when is large.


Level 3 — Analysis

Recall Solution L3.1

Set . Then the raw update factor is Predicted error scales as , so , so — comfortably under budget. That is exactly what the safety factor buys: even when we hit tol dead-on, the next step is predicted to land at ~59% of tol, so it is very likely accepted on the first try. This is the same trade-off drawn in the opening figure.

Recall Solution L3.2

Shrink factor .

  • Student X: drops to ~76% of old.
  • Student Y: halves. Because true local error , a factor-4 error overshoot only needs to fix. Student Y's exponent over-shrinks to , wasting steps: the retried step will come back at — 8× under budget, meaning the very next step immediately tries to grow again. Wrong exponent ⇒ oscillating, inefficient stepping. See Taylor Series Expansion for where the comes from.
Recall Solution L3.3

(a) Ratio . (b) → the clamp fires (recall from the opening definitions). (c) . The error model is only trustworthy locally; a ~20× jump could leap into a region with completely different curvature, so we cap the growth at 5×.


Level 4 — Synthesis

Recall Solution L4.1

Attempt 1: reject. Stay at . Ratio . Factor (inside clamps). Attempt 2 (from with ): accept. Advance: . Now pick the step for the next interval: ratio , factor . Summary: rejected once (t stays 0), accepted second try (t advances to ≈0.06238), then grows slightly to ≈0.06744 for the next interval.

Recall Solution L4.2

(a) Attempts . (b) calls . (c) Wasted calls; fraction . A rejection rate around 10–15% is healthy — it means the controller is pushing to the edge of the tolerance rather than being timidly small.


Level 5 — Mastery

Recall Solution L5.1

Attempt 1 (): reject. Ratio . Factor (inside clamps, since ). Attempt 2 (): reject. Ratio . Factor . Attempt 3 (): accept. Advance: . Final: after two rejections and one acceptance. Notice the clamp never fired here; each shrink stayed well above of the previous .

Recall Solution L5.2

(a) Ratio . Raw factor . , so raw . (b) → the lower clamp fires. (c) . (d) A raw factor far below repeatedly is the fingerprint of a stiff region — an explicit adaptive method may thrash here; consider an implicit solver (see Stiff ODEs and Stability).

Recall Solution L5.3

Ratio .

  • Wrong (, exponent ): factor , .
  • Correct (, exponent ): factor , . The correct controller grows more (factor 2 vs 1.78). Reason: the error estimate tracks the 4th-order solution's error, which scales as ; a 32× error surplus permits a × step increase. Using underestimates how fast you may grow — safe but wasteful. The mnemonic stays: "Tol Over Error, to the Fifth-root."
Recall Solution L5.4

(a) Maximum shrink: . (b) → it violates the floor. (c) The solver must not silently take a sub-floor step. Standard behaviour (e.g. scipy's solve_ivp) is to either clamp up to and accept a slightly-too-large error with a warning, or abort with a "step size too small" failure. Blindly continuing to shrink is dangerous because (i) can underflow toward machine , where rounds back to and the integration stalls forever; and (ii) tens of thousands of micro-steps accumulate round-off that swamps the very accuracy you were chasing. Repeatedly hitting is the classic signal to switch to an implicit method built for stiff problems.


Connections

  • Runge–Kutta Methods (RK4) — the fixed-step method these embedded pairs extend.
  • Local vs Global Truncation Error — why the local error drives the controller.
  • Order of a Numerical Method — pins down the in .
  • Stiff ODEs and Stability — where L5.2, L5.4 and the endless-rejection trap come from.
  • Taylor Series Expansion — source of the leading error term.
  • Dormand–Prince (RK45 used by scipy solve_ivp) — the coefficient table behind the stages and the RMS norm convention.
  • Hinglish version →