Change parameters · Explore this notebook model
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.
Python runs on this device. The first run loads the scientific libraries.
From a midpoint balance to a rotation matrix
Write a two-component oscillator as \(v'=\omega Jv\), where \(J\) sends \((x,y)\) to \((-y,x)\). Choosing scaled coordinates makes both components comparable; for a mechanical oscillator one may take displacement and a suitably scaled speed. The generator is skew-symmetric, so \(d(v^Tv)/dt=\omega v^T(J^T+J)v=0\). The exact motion has angular advance \(h\omega\) over an interval \(h\).
Midpoint approximates the velocity at the midpoint of the segment joining the old and new states. This yields \((I-aJ)v_{n+1}=(I+aJ)v_n\) with \(a=h\omega/2\). Since \(J^2=-I\), multiplication by \(I+aJ\) eliminates the inverse and gives
The coefficients of \(I\) and \(J\) have squares summing to one. They are the cosine and sine of the angle \(\theta_h=2\arctan a\). Thus every update preserves the squared radius. The angle differs from the exact \(h\omega\). Expanding the arctangent gives
Over a fixed duration \(T=nh\), the leading accumulated angle error is \(-T\omega^3h^2/12\). This phase lag is especially visible after many periods even when a graph of energy looks perfect.
For comparison, explicit Euler takes the tangent line to its end point. Its amplification is \(\sqrt{1+(h\omega)^2}\). Studying both amplitude and timing identifies different defects of the two updates.
Put a clock on the unit circle
Let \(\omega=2\) rad/s, \(h=0.5\) s and \(v_0=(1,0)\). The half-step parameter is 0.5. The rotation sends the first point to \((0.6,0.8)\) instead of the exact \((\cos1,\sin1)\approx(0.5403,0.8415)\). Both radii are one. The angular deficit is \(1-2\arctan(0.5)\approx0.072705\) rad per update. After ten updates, the numerical clock is behind by 0.72705 rad or about 0.364 s of physical time.
With \(h=0.25\) s over the same five seconds the deficit is \(10-40\arctan(0.25)\approx0.20085\) rad. Its ratio to the coarse-step error is close to one quarter. In the notebook the rotation is built by a linear solve and its angle is measured from a dot product and an oriented area. These are independent ways to check the hand formula. Counting full turns requires retaining unwrapped increments; a final point alone cannot identify the number of completed turns.
Set the experimental inputs
Edit these values, then run the calculation and both figures again.
The three markers correspond to one physical time step. The midpoint result lies on the circle at its own numerical angle.
The full and half steps cover the same physical interval. The dotted trace is the leading asymptotic error for the coarse step.
Exercise · reverse the sign of time
Show why a forward midpoint update followed by one equal backward update returns to the starting state. Does forward Euler have the same property here?
Replacing \(a\) by \(-a\) interchanges the two factors in the Cayley formula, so \(R_{-h}=R_h^{-1}\). Their product is the identity. For explicit Euler the product is \((I-h\omega J)(I+h\omega J)=(1+(h\omega)^2)I\). The reversal increases every radius when the angular speed and the step are nonzero.
Exercise · set a phase budget
For \(\omega=2\) rad/s, approximate a time step that keeps the accumulated phase lag below 0.02 rad over six seconds. Give an exact way to check the choice.
The leading magnitude is \(T\omega^3h^2/12=4h^2\). Equating this to 0.02 gives about 0.0707 s. Choosing 90 equal steps over six seconds gives \(h=1/15\) s. The exact lag is \(12-180\arctan(1/15)\) rad, about 0.0177. The exact check is useful when the step is large enough that the cubic series term has limited accuracy.