Before the steady state

The phase the rule loses

An inductor and a capacitor with no resistance ring for ever, and two ways of marching them disagree about how. The trapezoidal rule keeps the amplitude exactly — its factor per step has a magnitude of one — and loses phase instead: 2π − 2N·atan(π/N) a cycle, 2.918° at twenty steps a cycle, so ten cycles later it is 29.2° behind the circuit. Backward Euler keeps 0.3901 of the amplitude a cycle at the same step, and after ten cycles 0.0082 per cent of the ringing is left, in a circuit that has no loss. The two errors fall at different rates: the trapezoidal rule's phase as the square of the steps a cycle, backward Euler's amplitude as the first power. A hundred cycles to within one per cent needs 182 steps a cycle of one and 196,404 of the other.

Assumes: One step, computed twice · Resonance, and the bandwidth it sets exactly

The ringing that belongs to the rule found the trapezoidal rule’s weakness on a pole it cannot resolve: a factor per step that approaches −1, so a fast pole’s error is flipped rather than killed and rings at half the stepping rate. Backward Euler, whose factor goes to zero, has no such ringing. On that evidence backward Euler is the safer rule.

The same property, pointed at a different pole, reverses the verdict. One step, computed twice said the trapezoidal rule preserves the amplitude of a lossless oscillation exactly, at the cost of slightly mis-stating its frequency, and that backward Euler decays a lossless resonance visibly faster than the real one with nothing in the picture to say so. Both statements were qualitative. This essay marches a resonance that should never decay and measures what each rule does to it — in degrees and in nepers, per cycle, as a function of how many steps a cycle the march takes.

The resonance being marched is the one the frequency field measures in closed form. Resonance, and the bandwidth it sets exactly found its half-power width f0/Qf_0/Q to every digit, and the Q the components allow found the quality factor capped by the parts’ own losses; a backward-Euler march adds a loss no part has, and caps the simulated quality factor the same way. Where the behaviour is written down puts this circuit’s two poles exactly on the imaginary axis — the one place a rule’s factor per step has to have magnitude one to be right.

A resonance with nothing to lose

The circuit is an inductor of ten millihenries and a capacitor chosen to resonate with it at one kilohertz, driven by a one-volt step with no resistance anywhere in the loop. The capacitor’s voltage is exactly 1cosωt1 - \cos\omega t: it rises to two volts, falls to zero, and does that for ever, because nothing in the circuit dissipates. Any decay a march shows is the march’s, and any drift in phase is the march’s.

Each rule advances the circuit by a fixed linear map per step, so the capacitor’s distance from one volt obeys a two-term recurrence, ek+1=pekqek1e_{k+1} = p\,e_k - q\,e_{k-1}, with qq the square of the magnitude of the rule’s factor per step and pp twice that magnitude times the cosine of its angle. The figures fit pp and qq by least squares over the whole marched record, which is exact for a recurrence of that form and needs no zero crossings or fitted envelopes, and read off each rule’s rotation and decay per step. They are then checked against closed forms to a part in a million.

Ten cycles, marched

At 20 steps a cycle, ten cycles of an undamped LC: the trapezoidal rule keeps the amplitude and falls 29.2° behind; backward Euler keeps 0.0082% of itMarched, both rules, against 1 − cos ωt for a 1 kHz inductor–capacitor pair stepped with no resistance at all. At 20 steps a cycle the trapezoidal march's amplitude stays at 1.00000 a cycle and its frequency is slow: it loses 2.918° a cycle, measured from the march's own recurrence, against 2π − 2N·atan(π/N) = 2.918°, so after ten cycles it is 29.2° behind. Backward Euler keeps 0.3901 of its amplitude a cycle, against (1 + (2π/N)²)^(−N/2) = 0.3901, so 0.0082% is left after ten, and it loses 11.19° a cycle. No resistance is in the circuit; every loss is the rule's.0120246810time (milliseconds)capacitor voltage (volts), for a 1 V steptrapezoidalamplitude ×1.0000 a cycle…phase lost a cycle2.92°backward Euleramplitude ×0.3901 a cycle…phase lost a cycle11.19°exact1 − cos ωtmarched, no resistance anywherethe rule's loss, and the rule's lag
Fig. 1 Ten cycles of a 1 kHz inductor–capacitor pair stepped with no resistance, marched at 20 steps a cycle by both rules, against 1 − cos ωt. The trapezoidal march keeps its amplitude, 1.00000 a cycle, and loses 2.918° a cycle, 29.2° after ten. Backward Euler keeps 0.3901 of its amplitude a cycle, so 0.0082% is left after ten, and loses 11.19° a cycle. The slider is the steps a cycle.

At twenty steps a cycle the two marches look nothing alike. The trapezoidal one is a sinusoid of the right height, swinging from zero to two volts every cycle, slightly slow: it loses 2.918 degrees a cycle, and after ten cycles it is 29.2 degrees behind the circuit. Its amplitude per cycle is 1.00000 — the figure checks it to a part in a billion. The backward-Euler march collapses. It keeps 0.3901 of its swing each cycle, and after ten cycles 0.0082 per cent of the ringing is left: the march has settled at one volt, in a circuit with no resistance, as though the resonance had a quality factor of a little over three.

Both are wrong. Only one of them looks wrong. A designer who sees the trapezoidal waveform would accept it; one who sees the backward-Euler waveform might well accept that too, if the circuit were believed to have some loss, and the invented damping would then be read as a property of the components.

What each rule does to a pole on the axis

A lossless resonance is a pair of poles at ±jω\pm j\omega. With a step hh, the trapezoidal rule’s factor per step for such a pole is (1+jωh/2)/(1jωh/2)(1 + j\omega h/2)/(1 - j\omega h/2), whose magnitude is exactly one and whose angle is 2arctan(ωh/2)2\arctan(\omega h/2). Backward Euler’s is 1/(1jωh)1/(1 - j\omega h): magnitude 1/1+(ωh)21/\sqrt{1 + (\omega h)^2}, angle arctan(ωh)\arctan(\omega h).

So the trapezoidal rule rotates by slightly less than ωh\omega h each step and never shrinks: over NN steps a cycle, ωh=2π/N\omega h = 2\pi/N, it falls behind by

2π2NarctanπN2\pi - 2N\arctan\frac{\pi}{N}

radians a cycle, which is 2.918° at twenty steps. Backward Euler both rotates by less — 2πNarctan(2π/N)2\pi - N\arctan(2\pi/N) a cycle, 11.19° at twenty steps — and shrinks by (1+(2π/N)2)N/2(1 + (2\pi/N)^2)^{-N/2} a cycle, 0.3901 at twenty. The figure’s measured values agree with all three to a part in a million.

The two rules are the same kind of approximation to ejωhe^{j\omega h} — both rational, both of low order — and they spend their error differently. The trapezoidal rule’s factor lies exactly on the unit circle, where the true factor lies, and is wrong only in angle. Backward Euler’s lies inside the circle and is wrong in both. That one geometric fact is the whole difference between a march that keeps a resonance ringing slightly slow and one that kills it.

At 10 steps a cycle, ten cycles of an undamped LC: the trapezoidal rule keeps the amplitude and falls 111.9° behind; backward Euler keeps 0.000006% of it. Marched, both rules, against 1 − cos ωt for a 1 kHz inductor–capacitor pair stepped with no resistance at all. At 10 steps a cycle the trapezoidal march's amplitude stays at 1.00000 a cycle and its frequency is slow: it loses 11.188° a cycle, measured from the march's own recurrence, against 2π − 2N·atan(π/N) = 11.188°, so after ten cycles it is 111.9° behind. Backward Euler keeps 0.1894 of its amplitude a cycle, against (1 + (2π/N)²)^(−N/2) = 0.1894, so 0.000006% is left after ten, and it loses 38.58° a cycle. No resistance is in the circuit; every loss is the rule's.
Fig. 2 The same at 10 steps a cycle. The trapezoidal march loses 11.188° a cycle, 111.9° after ten, and keeps its amplitude; backward Euler keeps 0.1894 of its amplitude a cycle, so six millionths of a per cent is left after ten, and loses 38.58° a cycle.

At ten steps a cycle — coarse, but not unusual for a long simulation of a slow circuit that happens to contain a resonance — the trapezoidal march loses 11.2 degrees a cycle and is 112 degrees behind after ten cycles, a third of a cycle, with its amplitude still exactly right. Backward Euler keeps 0.1894 a cycle, so after ten cycles the ringing is down by a factor of sixteen million.

At 50 steps a cycle, ten cycles of an undamped LC: the trapezoidal rule keeps the amplitude and falls 4.7° behind; backward Euler keeps 2% of it. Marched, both rules, against 1 − cos ωt for a 1 kHz inductor–capacitor pair stepped with no resistance at all. At 50 steps a cycle the trapezoidal march's amplitude stays at 1.00000 a cycle and its frequency is slow: it loses 0.473° a cycle, measured from the march's own recurrence, against 2π − 2N·atan(π/N) = 0.473°, so after ten cycles it is 4.7° behind. Backward Euler keeps 0.6759 of its amplitude a cycle, against (1 + (2π/N)²)^(−N/2) = 0.6759, so 2% is left after ten, and it loses 1.88° a cycle. No resistance is in the circuit; every loss is the rule's.
Fig. 3 The same at 50 steps a cycle. The trapezoidal march loses 0.473° a cycle, 4.7° after ten; backward Euler keeps 0.6759 of its amplitude a cycle, 2% after ten, and loses 1.88° a cycle.

At fifty steps a cycle the trapezoidal march is 4.7 degrees behind after ten cycles and backward Euler has 2 per cent of its ringing left. At a hundred, 1.2 degrees and 14 per cent. The trapezoidal rule’s error has fallen by a factor of twenty-five for five times the steps, between twenty and a hundred; backward Euler’s loss per cycle, in nepers, has fallen by a factor of 4.8.

Two errors, two powers

Per cycle, the trapezoidal rule's phase error falls as N⁻² and backward Euler's amplitude loss as N⁻¹: a hundred cycles to 1% needs 182 and 196,404 steps a cycle. Marched over six cycles at each step count and measured, against the closed forms. The trapezoidal rule's phase lost a cycle falls as the −1.99 power of the steps a cycle and its amplitude is kept; backward Euler loses amplitude a cycle as the −0.97 power, and phase too. At 8 steps a cycle: trapezoidal 2.96e-1 rad a cycle; backward Euler 1.92e+0 nepers of amplitude and 9.57e-1 rad. At 32 steps a cycle: trapezoidal 2.01e-2 rad a cycle; backward Euler 6.05e-1 nepers of amplitude and 7.89e-2 rad. At 128 steps a cycle: trapezoidal 1.26e-3 rad a cycle; backward Euler 1.54e-1 nepers of amplitude and 5.04e-3 rad. To be within 1% of a cycle in phase after a hundred cycles the trapezoidal rule needs 182 steps a cycle; to keep 99% of the amplitude over a hundred cycles backward Euler needs 196,404.
Fig. 4 Each rule’s error a cycle against the steps a cycle, from 8 to 128, measured and set against the closed forms. The trapezoidal rule’s phase lost a cycle falls as the −1.99 power; backward Euler’s amplitude lost a cycle, in nepers, as the −0.97 power, and its phase lost as the square. To be within 1% of a cycle in phase after a hundred cycles the trapezoidal rule needs 182 steps a cycle; to keep 99% of the amplitude over a hundred cycles backward Euler needs 196,404.

Swept from eight steps a cycle to 128, the two errors separate onto different slopes. The trapezoidal rule’s phase lost a cycle falls as the square of the steps a cycle — the figure fits −1.99 and checks it within a tenth — because 2arctan(π/N)2\arctan(\pi/N) differs from 2π/N2\pi/N by a cubic term, and NN of them make a square. Backward Euler’s amplitude lost a cycle, measured in nepers, falls only as the first power — fitted −0.97 — because N2ln(1+(2π/N)2)\tfrac{N}{2}\ln(1 + (2\pi/N)^2) tends to 2π2/N2\pi^2/N. Its phase error falls as the square, like the trapezoidal rule’s, and four times larger.

The powers turn into step counts that are not close. To stay within one per cent of a cycle in phase over a hundred cycles, the trapezoidal rule needs 182 steps a cycle. To keep 99 per cent of the amplitude over the same hundred cycles, backward Euler needs 196,404. The first-order loss is not a detail a finer step removes in practice; it is a loss that needs a thousand times the work to push below one per cent.

The same warping a digital filter pre-corrects

The trapezoidal rule’s slow frequency has a closed form that deserves a name, because it has one elsewhere. A pole at jωj\omega marched with a step hh oscillates at

ωnum=2harctanωh2,\omega_{\text{num}} = \frac{2}{h}\arctan\frac{\omega h}{2},

and that is exactly the frequency warping of the bilinear transform, which is the trapezoidal rule applied to a filter’s differential equation to turn it into a digital one. The corner that moved measured the same compression from the digital side: a corner designed in continuous time and translated by the bilinear transform lands below where it was put, by the arctangent above, and the standard remedy is to pre-warp the design so that the corner lands where it was meant to.

A circuit simulator does not pre-warp. It cannot, because it does not know which frequencies the circuit will ring at before it marches it, and the warping is a function of each resonance’s own ωh\omega h. So a simulated resonance at one kilohertz, stepped at twenty steps a cycle, rings at 991.9 hertz — slow by 2.918 degrees a cycle, which is 0.81 per cent — and one at a tenth of a kilohertz, stepped at the same absolute step, rings at 99.99 hertz. The error is not a fixed fraction of the frequency; it is a fraction that grows as the square of the frequency against the step, and it is largest on exactly the resonances a simulation resolves least well.

Backward Euler has a warping of its own, arctan(ωh)/h\arctan(\omega h)/h, four times as large at small ωh\omega h, and a decay on top of it. No digital filter is designed with backward Euler for that reason, and the same reason argues against using it to simulate anything that rings.

A simulation that runs for a second

The step counts above are per cycle, and a simulation is set by a duration. Put a realistic resonance into a realistic run and the two rules’ requirements come apart by orders of magnitude.

Take a converter’s output filter resonating at ten kilohertz, simulated for one second to watch a slow control loop settle — ten thousand cycles of the resonance. For the ringing’s timing to stay within a tenth of a cycle at the end, the trapezoidal rule’s phase error of about (2π)3/(12N2)(2\pi)^3/(12N^2) radians a cycle, accumulated over ten thousand cycles, must stay below 0.2π0.2\pi: that needs about 570 steps a cycle, 5.7 million steps for the second. For backward Euler to keep ninety-nine per cent of the ringing’s amplitude over the same ten thousand cycles, its loss of 2π2/N2\pi^2/N nepers a cycle must total under a hundredth: that needs about twenty million steps a cycle, two hundred billion for the second.

Neither simulation is run that way. The trapezoidal one is usually run coarser, and its resonance drifts in phase by a fraction of a cycle that nobody checks because the waveform still looks like a resonance. The backward-Euler one, when a simulator falls back to it, is run at the same coarse step and simply shows no resonance — the filter appears critically damped, and the control loop’s settling is simulated against a plant that does not exist.

Which error a simulation can live with

A lost degree of phase and a lost per cent of amplitude are not the same kind of error, and the comparison depends on what the simulation is for.

For anything that measures a decay, the trapezoidal rule is the only choice. A quality factor read off a marched ring-down, a settling time on a lightly damped loop, the tail of a resonance excited by a switching edge — each of these is an amplitude against time, and backward Euler adds a decay rate of 2π2/N2\pi^2/N nepers a cycle to whatever the circuit has. At a hundred steps a cycle that is 0.197 nepers a cycle, equivalent to a quality factor of about sixteen in parallel with the circuit’s own; a resonance whose true quality factor is fifty would be read at about twelve.

For anything that measures a time, both rules carry a phase error, and the trapezoidal rule’s is a quarter of backward Euler’s. A frequency read off zero crossings, a delay through a resonant network, the timing of a switching event triggered by a ringing node: all of these accumulate the phase lost per cycle, and after enough cycles they are wrong by a whole cycle. At twenty steps a cycle the trapezoidal rule loses a whole cycle every 123 cycles.

And a long simulation of a lightly damped resonance should be judged by its phase budget. The trapezoidal rule’s phase error per cycle is about (2π)3/(12N2)(2\pi)^3/(12N^2) radians, so the number of cycles before it has lost a given fraction of a cycle grows as N2N^2; doubling the steps a cycle quadruples the cycles a simulation can run before its timing is wrong. That is the number to set a step by when a resonance is being simulated for many periods, and it is not the number an error control based on local truncation will choose.

Telling the two errors apart on a real run

The rule of thumb for false ringing — shorten the step and see whether it changes — has a counterpart here, and the powers make it quantitative. Run the same simulation at a step and at half that step, and compare the resonance’s phase at the end of the run. If the march is trapezoidal, its phase lag should shrink by a factor of four, because the lag per cycle goes as the inverse square of the steps a cycle; if what remains after halving is a quarter of what was there, the lag was the rule’s, and a further halving will leave a sixteenth.

The amplitude says the same about backward Euler with a different number. A decay rate invented by the rule halves when the step halves, because it goes as 2π2/N2\pi^2/N; a decay rate that belongs to the circuit does not move. So a ring-down whose decay rate falls by half when the step is halved was mostly the rule’s, and one whose decay rate is unchanged was the circuit’s. Two runs, one comparison each, and the measurement says which part of a simulated resonance is a simulation.

Neither test is free, and both are cheaper than being wrong: halving the step doubles the work once, where an unrecognised invented damping can put a control loop’s design against a plant that does not exist.

Where the two essays meet

The two measurements on this subject point in opposite directions, and they are the same fact about two factors.

On a real pole far faster than the step, the trapezoidal factor tends to −1 and backward Euler’s to zero, and backward Euler is right: the pole should be dead within a step, and the trapezoidal rule rings instead. On an imaginary pole, the trapezoidal factor has magnitude one and backward Euler’s is less, and the trapezoidal rule is right: the pole should never decay, and backward Euler kills it. A rule whose factor sits on the unit circle along the whole imaginary axis cannot also send the far left of the plane to zero, because a rational function that does both would have to change its magnitude discontinuously at infinity.

Per step, the trapezoidal rule multiplies a fast pole's error by −0.818 at h = 20τ and −0.980 at 200τ; backward Euler by 0.048 and 0.005. Closed form, held to the march. The factor each rule multiplies a single real pole's error by in one step, against the step over the time constant: exact e^(−h/τ), trapezoidal (1 − h/2τ)/(1 + h/2τ), backward Euler 1/(1 + h/τ). Measured on the marched fast node at h/τ = 0.5, 5, 20, 200: trapezoidal 0.6000, −0.4286, −0.8182, −0.9802; backward Euler 0.6667, 0.1667, 0.0476, 0.0050. The trapezoidal factor crosses zero at h = 2τ and approaches −1 as the step grows, so it takes 23 steps to fall to 1% at 20τ and 231 at 200τ; backward Euler takes 2 and 1.
Fig. 5 The factor each rule multiplies a single real pole’s error by in one step, against h/τ: exact eh/τe^{-h/\tau}, trapezoidal (1 − h/2τ)/(1 + h/2τ), backward Euler 1/(1 + h/τ). The trapezoidal factor crosses zero at h = 2τ and approaches −1; backward Euler’s approaches zero.

On the real axis the ordering is the reverse of the imaginary axis’s. The figure is the earlier measurement’s: the trapezoidal factor tends to −1 for a pole far faster than the step and backward Euler’s to zero, so on a pole that should die the trapezoidal rule is the one that is wrong. Set beside the lossless resonance, the two figures are one statement about two rational approximations to an exponential, read along the two axes of the plane where they disagree most.

That is why simulators mix them. The ringing that belongs to the rule took one or two backward-Euler steps after a discontinuity to kill the fast pole’s false ringing and then returned to the trapezoidal rule; the measurement here says what those steps cost a resonance that is ringing at the time. At twenty steps a cycle one backward-Euler step shrinks a resonance by (1+(2π/20)2)1/2(1 + (2\pi/20)^2)^{-1/2}, 0.954 — a loss of four and a half per cent of amplitude in one step, applied every time a discontinuity occurs. A converter model with a switching event every cycle and a resonant tank ringing through them would lose that fraction of its tank amplitude per switching event to the remedy alone.

Still open: the second-order rules that damp, the step error control chooses, and a resonance with its own loss

A rule between the two. The second-order backward differentiation formula has a factor that goes to zero for fast poles, like backward Euler, and loses amplitude on the imaginary axis only at second order. Measuring its phase and amplitude errors per cycle beside these two would say how much of the trapezoidal rule’s accuracy on a resonance it keeps while losing the false ringing, which is the trade a circuit simulator makes when it offers it.

Error control on a resonance. A variable-step march sets its step by estimating the local error from two rules at each step. On a lossless resonance the local error per step is tiny — third order in the step for the trapezoidal rule — and the accumulated phase error is not local at all. Whether error control lets a long ringing simulation drift a cycle behind while reporting every step within tolerance is the practical form of the phase budget above.

A resonance with loss of its own. With a resistor in the loop the true decay competes with backward Euler’s invented one, and the trapezoidal rule’s factor moves off the unit circle by exactly the right amount at first order. Two numbers without solving for the waveform marched such a circuit for sixty cycles at two hundred steps a cycle and found the phase error growing as the damping fell; putting a number on how a rule’s error in decay rate compares with a circuit’s true decay rate would say at what quality factor backward Euler’s damping dominates the circuit’s.

Part 3 on step response

One argument about Step response, and one of 3 essays on it so far, each part numbered by how much of the idea it assumes. What sits either side of it:

What links here

Essays that reach for this one mid-argument — the half of a link its own author cannot write down.

The objects named here

The third axis, after the field and the idea: the things themselves, and every essay that touches each one.

Convergence orderLossless networkMarchingModel rangeNumerical errorStep responseTrapezoidal rule