Adaptive step-size controller (source code)

= Adaptive step-size controller
{title2=$h_{\rm new}=h\,\eta E^{-1/r}$}

If a scaled <local error estimator> behaves as $E\propto h^r$ with approximately unchanged error scale, the displayed update targets a fixed local level. A safety factor $0<\eta<1$ aims below the acceptance boundary. For an <embedded Runge-Kutta pair> with <order of a numerical method> $p$ for the accepted output and $p-1$ for the companion formula, the difference generally has $r=p$; for the actual unscaled <local truncation error> of an order-$p$ formula, $r=p+1$. The exponent belongs to the quantity being controlled. Dividing the defect by $h$ changes that exponent. This follows by solving $E(h_{\rm new})\approx E(h)(h_{\rm new}/h)^r$ for the next step.<Fundamentals of Numerical Computation by Tobin A. Driscoll and others>[§6.5.1, equations (6.5.1)–(6.5.4): estimator order and step prediction]{ref}

Rejecting a trial means retrying from the same accepted time and state, with a smaller step. Advancing time or retaining the rejected output would change the <initial value problem> being approximated. Minimum and maximum change factors prevent extreme updates; a zero estimate requires finite capped growth. After acceptance, cap the next step at the remaining interval length. Detect a step that cannot advance time in <floating-point arithmetic>, and report failure rather than an endless retry. An <adaptive step-size controller> can use earlier estimates to smooth step sequences, but the memoryless rule here is sufficient to explain acceptance and rejection.<Fundamentals of Numerical Computation by Tobin A. Driscoll and others>[§6.5.1, Algorithm 6.5.1; §6.5.3, rk23 implementation and About the code: retain state on rejection, safety factor, growth cap, final-step cap, nonadvancing-time check]{ref}