Skip to content

A numerical trajectory can preserve energy exactly and still follow the wrong clock. We demonstrate this with the implicit midpoint method for a harmonic oscillator: its update is an exact rotation, but its rotation angle differs from the physical one. The example separates an algebraic identity, a solved discrete equation, a continuous equation residual and a finite-time trajectory error. It also supplies negative controls capable of detecting a plausible wrong answer.

Required background. Matrix multiplication, Euclidean norms and the distinction between Lax isospectrality and correct dynamics.

Helpful background. Noncommuting limits and uniform validity explains why a small frequency error can accumulate over time.

Consider four statements about a calculation. “These matrices obey an identity for every parameter” requires an algebraic proof on the stated domain. “This vector solves the finite linear system” can be assessed by a residual and conditioning. “This discrete solution approximates a differential equation” needs consistency, stability and refinement. “This approximation remains accurate at late times” needs a time-dependent error estimate. Agreement in one test does not automatically answer the others.

A negative control changes something consequential while preserving an easy check. For example, a wrong sign in time evolution may preserve all energies while reversing the trajectory. A useful test must reject that modified answer. This is a way to inspect the diagnostic’s sensitivity, not an instruction to declare numerical disagreement a proof of nonintegrability.

Midpoint evolution is an exact discrete rotation

Section titled “Midpoint evolution is an exact discrete rotation”

Use dimensionless coordinates X=q/q∗X=q/q_* and Y=p/(mωq∗)Y=p/(m\omega q_*) for an oscillator with m,ω,q∗>0m,\omega,q_*\gt0. In physical time,

z˙=Az,z=(XY),A=ω(01−10).\dot z=Az,\qquad z=\begin{pmatrix}X\\Y\end{pmatrix},\qquad A=\omega\begin{pmatrix}0&1\\-1&0\end{pmatrix}.

The physical energy is mω2q∗2∥z∥22/2m\omega^2q_*^2\|z\|_2^2/2. For z(0)=(1,0)Tz(0)=(1,0)^T, the exact solution has components X(t)=cos⁡(ωt)X(t)=\cos(\omega t) and Y(t)=−sin⁡(ωt)Y(t)=-\sin(\omega t).

For time step h>0h\gt0, the implicit midpoint rule is

zn+1−znh=Azn+1+zn2.\frac{z_{n+1}-z_n}{h}=A\frac{z_{n+1}+z_n}{2}.

This linear equation has the unique update

zn+1=Mhzn,Mh=(I−hA/2)−1(I+hA/2).z_{n+1}=M_hz_n,\qquad M_h=(I-hA/2)^{-1}(I+hA/2).

Writing x=ωh/2x=\omega h/2, direct multiplication gives

Mh=11+x2(1−x22x−2x1−x2).M_h=\frac1{1+x^2} \begin{pmatrix}1-x^2&2x\\-2x&1-x^2\end{pmatrix}.

Thus MhTMh=IM_h^TM_h=I exactly, and the discrete energy is conserved in exact arithmetic for every hh. The angle is

θh=2arctan⁡(ωh/2),zn=(cos⁡nθh,−sin⁡nθh)T.\theta_h=2\arctan(\omega h/2),\qquad z_n=(\cos n\theta_h,-\sin n\theta_h)^T.

It follows that the numerical frequency is

ωh=θhh=ω−ω3h212+O(h4).\omega_h=\frac{\theta_h}{h} =\omega-\frac{\omega^3h^2}{12}+O(h^4).

Exact energy conservation has coexisted with a second-order frequency error. This explicit calculation is derived here. The broader distinction between conservation and quality of long-time motion is illustrated independently by Hairer 2006, §1.1.3, pp. 3–4, Figure 1.2, author PDF, where an energy projection can worsen a gravitational trajectory. No theorem about all energy-preserving methods is needed for the oscillator conclusion.

The midpoint discrete residual

dn=zn+1−znh−Azn+1+zn2d_n=\frac{z_{n+1}-z_n}{h} -A\frac{z_{n+1}+z_n}{2}

is zero in exact arithmetic. In code it checks whether the implemented linear update solves the method’s defining equation. It cannot measure the method’s discrepancy from the exact continuous trajectory, because that discrepancy exists even when dn=0d_n=0.

A smooth interpolant rotates at the numerical frequency ωh\omega_h and passes through every node,

z~h(t)=(cos⁡(ωht)−sin⁡(ωht)).\widetilde z_h(t)= \begin{pmatrix}\cos(\omega_h t)\\-\sin(\omega_h t)\end{pmatrix}.

Its continuous residual is

rh(t)=z~˙h−Az~h,∥rh(t)∥2=∣ωh−ω∣.r_h(t)=\dot{\widetilde z}_h-A\widetilde z_h, \qquad\|r_h(t)\|_2=|\omega_h-\omega|.

This named interpolant matters: a collection of nodes alone has no unique derivative. A piecewise linear or polynomial interpolant has a different pointwise residual.

An independent centered-difference test on the nodes gives a third quantity,

rncd=zn+1−zn−12h−Azn,∥rncd∥2=ω−sin⁡θhh=ω3h24+ω2h2.r_n^{\rm cd}=\frac{z_{n+1}-z_{n-1}}{2h}-Az_n, \qquad \|r_n^{\rm cd}\|_2 =\omega-\frac{\sin\theta_h}{h} =\frac{\omega^3h^2}{4+\omega^2h^2}.

It includes differentiation error as well as the method’s frequency error, so its coefficient differs from ω3/12\omega^3/12. Both residuals vanish as h2h^2; equating their numerical values would be a mistake. Refinement tests the named estimator, not a residual with unspecified differentiation.

Let z~\widetilde z be any differentiable trial curve, with residual r=z~˙−Az~r=\dot{\widetilde z}-A\widetilde z. If zz is the exact solution, variation of constants gives

z~(t)−z(t)=eAt[z~(0)−z(0)]+∫0teA(t−s)r(s) ds.\widetilde z(t)-z(t) =e^{At}[\widetilde z(0)-z(0)] +\int_0^te^{A(t-s)}r(s)\,ds.

Since AT=−AA^T=-A, its propagator is orthogonal, hence for t≥0t\ge0

∥z~(t)−z(t)∥2≤∥z~(0)−z(0)∥2+∫0t∥r(s)∥2 ds.\|\widetilde z(t)-z(t)\|_2 \le\|\widetilde z(0)-z(0)\|_2 +\int_0^t\|r(s)\|_2\,ds.

This explains why both initial data and dynamics must be checked. For midpoint interpolation the bound is t∣ωh−ω∣t|\omega_h-\omega|, while the exact node error is

∥zn−z(nh)∥2=2∣sin⁡nθh−ωnh2∣.\|z_n-z(nh)\|_2 =2\left|\sin\frac{n\theta_h-\omega nh}{2}\right|.

It is second order at fixed final time and can be order one at times proportional to h−2h^{-2}. For a general nonlinear equation z˙=f(z)\dot z=f(z) with Lipschitz constant LL on a region containing both curves, the analogous bound contains factors eL(t−s)e^{L(t-s)}. A small residual gives a useful small forward error only when the stability factors and time interval permit it.

A worked refinement and a negative control

Section titled “A worked refinement and a negative control”

Set ω=1\omega=1 and final time T=10T=10, with T/hT/h an integer. The exact formulas predict:

hhFrequency error 1−ωh1-\omega_hEndpoint error ∥zT/h−z(T)∥2\|z_{T/h}-z(T)\|_2
0.20.20.003313480.003313480.03313320.0331332
0.10.10.0008320860.0008320860.008320830.00832083
0.050.050.0002082550.0002082550.002082550.00208255

Halving hh reduces the error by approximately four. Energy drift is zero algebraically in every row, so it cannot reveal that convergence by itself. Floating-point iteration introduces a small drift, which is a separate implementation error.

Now replace the physical generator by −A-A in the update while still testing the original initial-value problem. The resulting trajectory rotates backward, remains exactly on the unit circle, and has zero residual for its own wrongly signed midpoint equation. Against the original ODE, its smooth-interpolant residual tends to 2ω2\omega, not zero. Checking the original equation independently rejects a bug that energy preservation and an internally reused update formula would miss.

The downloadable checks implement the linear solve, evaluate energies and both residuals, compare with the analytic rotation, and run this sign-reversal control. They also preserve the earlier wrong-frequency Lax test as a distinct example. Residual norms use dimensionless X,YX,Y; raw q,pq,p components have different units and should not be combined without scaling.

A symbolic calculation here proves exact finite-matrix identities. A numerical run checks that the program realizes those identities within stated arithmetic error. Refinement supports the predicted order for the tested initial condition and interval. None of these steps proves global completeness of a Bethe ansatz, an unbounded-operator identity or integrability of an arbitrary model. Conversely, one exact counterexample can refute a universal implication, provided it satisfies the implication’s hypotheses.

For a larger computation, keep discretization, finite-volume truncation, floating-point arithmetic and model approximation as distinct sources of error. An agreement obtained by using the same incorrect convention twice is particularly weak evidence. The Computational Methods volume develops solver-specific conditioning and convergence; this page establishes the logic that those checks must serve.

A small residual can drive a large error in a stable system

Section titled “A small residual can drive a large error in a stable system”

The oscillator bound used an orthogonal propagator. To see what changes without that assumption, take the dimensionless generator and a constant residual

A=(−1K0−1),r=(0δ). A=\begin{pmatrix}-1&K\\0&-1\end{pmatrix},\qquad r=\begin{pmatrix}0\\ \delta\end{pmatrix}.

Start both trajectories at zero. The exact unforced solution stays zero. The trial curve solves z~˙=Az~+r\dot{\widetilde z}=A\widetilde z+r. Its error therefore equals the integral of eAsre^{As}r from zero to tt. The strictly upper triangular part of AA squares to zero, giving

z~(t)=δ(K[1−(1+t)e−t]1−e−t). \widetilde z(t)=\delta\begin{pmatrix} K[1-(1+t)e^{-t}]\\1-e^{-t} \end{pmatrix}.

Both eigenvalues of AA are −1-1. Nevertheless the coupling can amplify error in the first component: with K=100K=100, δ=10−3\delta=10^{-3} and t=5t=5, that component is about 0.095960.09596. In contrast, the residual norm stays at 0.0010.001. The observed amplification comes from the off-diagonal entry of the propagator. A stability estimate for this calculation must retain that entry. Check the response by exponentiating the augmented system (Python)

  1. Energy projection. Normalize the explicit Euler step by writing

    zn+1=(I+hA)zn1+ω2h2.z_{n+1}=\frac{(I+hA)z_n}{\sqrt{1+\omega^2h^2}}.

    Find its rotation angle and leading frequency error. Does it conserve the unit-circle energy?

  2. An initial-data error. Let z~(t)=2z(t)\widetilde z(t)=2z(t). Which residual vanishes? Why does the forward error remain nonzero?

  3. A false algebraic inference. A parameter-dependent matrix expression vanishes at one hundred chosen values. State an additional degree bound that would make a finite scalar polynomial test conclusive, and explain why arbitrary rational or transcendental expressions need more care.

Solutions and checks
  1. The angle is arctan⁡(ωh)\arctan(\omega h), so the frequency is ω−ω3h2/3+O(h4)\omega-\omega^3h^2/3+O(h^4). The step is orthogonal and conserves energy exactly. Its leading phase error is four times that of midpoint.
  2. The ODE residual is zero by linearity, but the initial discrepancy is ∥z~(0)−z(0)∥2=1\|\widetilde z(0)-z(0)\|_2=1. Orthogonal evolution preserves it. An equation residual without the initial condition does not identify the requested solution.
  3. A scalar polynomial of degree at most 99 vanishing at 100 distinct exact points is identically zero. Apply this entrywise if the same degree bound is proved for a matrix polynomial. Floating-point near-zeros are not exact zeros; rational expressions require control of denominators and poles, and a transcendental expression has no such degree bound.
  • Hairer, Ernst. “Long-Time Energy Conservation.” In Foundations of Computational Mathematics, Santander 2005, edited by Luis M. Pardo, Allan Pinkus, Endre Süli, and Michael J. Todd, 162–180. Cambridge University Press, 2006. Publisher chapter. Author manuscript titled “Long-time energy conservation of numerical integrators”; PDF. Locators above use its own pp. 3–4.