Build a method from a centred difference
Integrate \(y'=f(t,y)\) over an interval of length \(h\). Midpoint quadrature approximates the integral by \(h\) times its integrand at \(t_n+h/2\). The arithmetic mean of the unknown endpoint states approximates the exact midpoint state up to order \(h^2\) on a smooth trajectory. Using this mean as the derivative's state argument gives
Errors from midpoint quadrature and from evaluating \(f\) at the approximate midpoint both contribute \(O(h^3)\) locally, giving global order two on a fixed interval under the usual regularity and stability conditions. In general the unknown appears inside \(f\), so an implicit equation must be solved. If \(f\) is Lipschitz with constant \(L_f\), direct fixed-point iteration contracts when \(|h|L_f/2<1\). Newton iteration can converge over a wider range. Neither a failed nonlinear solve nor loose tolerances inherit the exact algebraic properties of the method.
Exchange \(y_n,y_{n+1}\) and replace \(h\) by \(-h\). The left side changes sign, the arithmetic midpoint is identical and the midpoint time is identical if the reverse step starts at \(t_{n+1}\). Thus, on the same locally unique solution branch,
A round trip using variable steps must repeat the accepted steps in reverse order. Independently choosing a new adaptive mesh on the way back need not retrace the states.
Solve the step for a harmonic oscillator
Write \(q'=\omega p,\ p'=-\omega q\), with scaled momentum \(p\) in the same units as \(q\), and \(z=q+ip\). The ODE becomes
Solving the linear midpoint equation gives the scalar multiplier
Its numerator and denominator are complex conjugates. Hence it preserves \(q^2+p^2\), proportional to the oscillator energy, exactly in real arithmetic. For any radius or step size \(M(-u)M(u)=1\). The rotation per step is
The numerical phase lags by \(u-\theta\) per step. After \(N\) steps the accumulated lag is \(N(u-\theta)\), increasing linearly in elapsed time even while the energy remains exactly constant.
Compare explicit midpoint Runge–Kutta. A half Euler predictor leads to
It also has order two, but \(|M_{\rm RK2}|^2=1+u^4/4\). The amplitude grows slowly at every nonzero step. A forward and reverse pair multiplies the starting amplitude by \(1+u^4/4\). In a conservative problem these two second-order procedures can produce visibly different long records.
Inspect the return and the lag separately
With \(\omega=1\), \(h=0.5\), \(N=20\), exact accumulation is 10 radians. Midpoint gives \(40\arctan(0.25)=9.7991\) radians, a lag of \(0.2009\) radians. The explicit round trip multiplies the radius by \((1+0.5^4/4)^{20}\simeq1.364\). The implicit round trip returns the original radius and phase to roundoff. Run both updates below. Compare results at equal elapsed time by halving \(h\) and doubling \(N\). The phase error should drop by about a factor of four. The graph uses computed steps for the methods and a more finely sampled exact reference.
Tutorial on designing an accuracy criterion
A solver preserves the harmonic energy exactly over a simulation of 100 time units with \(\omega=1\). A measurement also requires phase error below 0.01 radians. Use the leading midpoint error to estimate an admissible step. How would you verify it?
Work through the solution
The accumulated phase error is approximately \(T\omega^3h^2/12\). Solving \(100h^2/12<0.01\) gives \(h<0.0346\). Verify at a chosen integer step count using \(T-2N\arctan[T/(2N)]\), or by convergence against a refined trajectory that measures the phase continuously. Energy alone has zero error for all these steps, so it cannot certify the phase target.
Further reading · Hairer's TUM geometric numerical integration course, symmetric methods.