Mathematics / Adaptive RKF45 Integration
FREE TO EXPLORE
LABORATORY 34 · MATHEMATICS

Adaptive RKF45 Integration theory

Understand adaptive rkf45 integration: mathematical proofs, error recurrences, asymptotic rates and stability criteria.

Mathematical foundations of Adaptive RKF45 Integration.

In realistic computational physics and engineering simulations—from planetary spacecraft trajectories navigating close lunar flybys to chemical combustion fronts—dynamical timescales change by orders of magnitude along a single trajectory. Forcing a fixed step size results in either intolerable inaccuracy in violent regions or massive computational waste in smooth regions. Erwin Fehlberg made a historic breakthrough in 1969 by designing embedded Runge-Kutta pairs: two Runge-Kutta methods of orders p and p + 1 sharing the exact same intermediate stage evaluations. By subtracting the two solutions, the solver obtains a rigorous estimate of the local truncation error without performing any extra function evaluations, enabling automatic closed-loop PI step size adaptation. In this computational laboratory, we implement the embedded RKF45 algorithm, analyze the six-stage Butcher tableau, and verify the fifth-order O(h⁵) local error scaling.

ln(E_local) = α · ln(h) + ln(C)

Viva voce questions & analytical theory

Why is fixed-step integration inefficient for systems with multiscale dynamics?

In physical systems like celestial orbits or chemical kinetics, solutions alternate between tranquil phases (where large step sizes maintain high accuracy) and violent shock/periapsis passages (where tiny steps are mandatory). A fixed-step integrator must use the worst-case tiny step size throughout the entire trajectory, wasting massive computational resources.

How does an embedded Runge-Kutta pair estimate error for free?

An embedded pair uses a shared set of stage evaluations k_1, ..., k_s to construct two different solutions: y_p of order p and y_{p+1} of order p + 1. Because y_{p+1} is much more accurate than y_p, the difference E = y_{p+1} - y_p provides an asymptotically exact estimate of the local truncation error of y_p without requiring any extra function evaluations.

How is the step-size adaptation formula derived?

Because the local truncation error scales as E ≈ C · h^{p+1}, the target error at a new step size h_{new} is TOL ≈ C · h_{new}^{p+1}. Dividing these gives TOL / E = (h_{new} / h)^{p+1}. Solving for h_{new} yields h_{new} = h · (TOL / E)^{1/(p+1)}. A safety factor S ≈ 0.9 is applied to prevent marginal rejections.

What is the Dormand-Prince (DOPRI5) method and how does it improve on RKF45?

Dormand and Prince (1980) optimized Fehlberg's tableau to minimize the error coefficient of the higher-order solution (local extrapolation). Additionally, DOPRI5 possesses the First Same As Last (FSAL) property: the last stage k_7 equals the first stage k_1 of the next step, effectively reducing the cost from 7 stages to 6 stages per accepted step. It serves as MATLAB's ode45 and SciPy's default RK45.

What happens when an adaptive integrator encounters a step rejection?

When E > TOL, the step is rejected: the solution state is not advanced, the time step is reduced according to the adaptation formula (clamped to prevent collapse), and the step is recomputed. An efficient controller maintains a rejection rate below 5-10%.

What are step-size limiter bounds (e.g. 0.2 and 5.0)?

To prevent wild numerical step oscillations caused by local fluctuations or roundoff error, step growth is restricted to at most a factor of 5 (h_{new} ≤ 5 h), and step reduction is limited to at most a factor of 0.2 (h_{new} ≥ 0.2 h).

What is local extrapolation in adaptive Runge-Kutta methods?

In local extrapolation, the higher-order solution y_{p+1} (5th order in RKF45) is used to advance the trajectory rather than the lower-order solution y_p (4th order), even though the error estimate was derived for y_p. This provides a free boost in global accuracy.

Algorithm precautions and stability rules

  • Store Fehlberg's rational tableau coefficients as exact fractions or 17-digit floating point constants to preserve 5th-order cancellation.
  • Enforce strict clamping bounds (e.g. 0.2 ≤ h_{new}/h ≤ 5.0) to prevent numerical instability and sudden step-size explosion.
  • Ensure local error E is evaluated in an appropriate norm (RMS norm or max norm scaled by absolute and relative tolerances).
  • Do not allow step size to shrink below machine precision times current time (h < 10 ε_mach · t) to prevent infinite loops at singularities.
  • When a step is rejected, repeat the step immediately with the reduced step size rather than advancing the time variable.
  • Verify that floating point registers maintain 64-bit IEEE 754 precision during the six-stage linear combination.

Theoretical limitations

  • RKF45 is an explicit embedded pair; on stiff differential equations, the step controller will drastically shrink h to satisfy stability rather than accuracy.
  • Step-size adaptation can become jittery near non-smooth events (such as contact collisions), requiring event detection root-finding algorithms.
  • Dense output (continuous trajectory interpolation between accepted steps) requires additional Hermite or free interpolant evaluations.
↳
Connect theory to numerical computation.

The simulation evaluates the embedded local truncation error of the six-stage RKF45 algorithm across step sizes h = 0.20 / 2^{k-1}. The local error estimate scales with the fifth power of h. The logarithmic regression ln(E_local) = α·ln(h) + ln(C) extracts the asymptotic order α = 5.000 with R² = 1.000000.