FYI: backward Euler, trapezoidal, Gear
Hi all,
I wrote this as a reply to a question on sci.electronics.design, and
it occurred to me that folks here might be interested also. If not,
the delete button is easy enough...
The question was a common enough one: I see oscillations in my
waveform. If I switch to Gear integration, they go away. Does that
mean the trapezoidal integrator was at fault, or my circuit?
--Steve
---------------------------------------------------------------------
yitping_kok@yahoo.com writes:
> Now, I would like to gather some opinion or comments regarding this two
> algorithm. What is the nature of the Trapezoidal algorithm that could
> produce such oscillations?
The trapezoidal formula is x(n+1) = x(n) + h/2 * (x'(n+1) + x'(n)), or
rewritten a bit, x'(n+1) = -x'(n) + 2/h*(x(n+1) - x(n)), where the
n and n+1 refer to the previous and current timepoint.
The trapezoidal formula is used to approximate derivatives, for
instance i=q' -- so the problem should be obvious, and it comes in
through the -x'(n) term: If the previous step had some amount of
error, the trapezoidal formula preserves the error from step to step,
giving it alternating signs. That's where the sawtooth "trapezoidal
oscillation" comes from.
You can get this error from a sloppy solution and/or specific situations
having to do with index 2 differential-algebraic equations which arise
with the modified nodal equations.
Tightening tolerances will help. Getting a simulator where the
equations avoid this will help. Limiting your integrator to first
order (backward Euler) or switching to Gear methods will help, with
some small warnings, below...
> What is the difference between the two algorithm?
Backward Euler (BE), trapezoidal and Gear have their own peculiar
properties. Think of a pole-zero plot, with stable poles on the left,
unstable in the right. Numerical integrators also have stability
patterns, and trapezoidal is "best" in that it is stable in the left
hand plane only, so it matches "reality" in some sense. BE is stable
in all but a unit circle in the RHP, so it can make an unstable
circuit look stable -- same with Gear orders 1 and 2. Higher order
Gear methods (4 to 6) are fixed-step stable in smaller and smaller
regions of the LHP, so they can make a stable circuit look unstable.
> How can I make sure that the oscillation is really caused by
> the algorithm and not my circuit design?
If the oscillation has a half-period each timestep, e.g. looks like a
sawtooth, this corresponds to the alternating sign from the
trapezoidal -x'(n) term, and it is the algorithm. Try to tighten the
tolerances and look carefully at the oscillation. If the oscillation
becomes a sinusoid with multiple timepoints per period, it is the
circuit.
Unfortunately, SPICE's timestep control is buggy as a cheap hotel, but
that's another story...
--Steve
Partial thread listing: