A8 · Lesson 46 · Stiff equations
Why SPICE takes its steps backward
A circuit has a 1 µs time constant from a small bypass capacitor and a 1 s time constant from a big reservoir. You want to watch the slow one for a few seconds. With Euler's method, you'd expect to take steps of a few milliseconds. Try it and the simulation explodes to : the fast mode, long since decayed in the real circuit, comes back and grows without bound. Such problems are stiff, and every circuit simulator meets them constantly. The cure is an implicit method, which evaluates the slope at the end of each step instead of the start.
- Both methods solve (time constant 1) with step size . The smooth curve is the exact .
- Explicit (forward) Euler multiplies by each step; implicit (backward) Euler divides by .
- Push past 1, then past 2. What happens to each?
Predict
Forward Euler on with = 0.01. What happens?
It blows up. The factor per step is , so the error flips sign and grows ninefold every step. Forward Euler is stable only if , which needs here, however little you care about the fast mode.
Name it
Stability of a method
Apply a method to the test equation (). Each step multiplies by a factor ; the method is stable when .
| Method | Step | Factor | Stable for |
|---|---|---|---|
| forward (explicit) Euler | |||
| backward (implicit) Euler | every | ||
| trapezoidal | average of the two | every |
Stiffness
A system is stiff when its time constants span a huge range. The fastest mode sets the stability limit of an explicit method, even after it has decayed to nothing, while the slowest sets how long you must simulate. With time constants of 1 µs and 1 s, forward Euler needs about million steps.
Implicit methods
Backward Euler for needs a solve at every step:
That costs more per step, but the step size is now limited only by the accuracy you want for the slow modes. For a linear circuit is the same every step, so you factor it once (A7, lesson 9). SPICE uses the trapezoidal rule and Gear's methods, both implicit, for exactly this reason; for nonlinear circuits each step is a Newton solve.
Worked example
A circuit has time constants of 1 µs and 1 s. How many forward Euler steps does it take to simulate 5 s?
Show the solution
- Forward Euler's step limit. Stability needs µs µs.
- Count the steps. steps, all to resolve a mode that dies in the first few microseconds.
- Compare backward Euler. Backward Euler with = 10 ms, accurate enough for the 1 s mode, needs 500.
Answer forward Euler takes steps; backward Euler needs only 500.
Worked example
Backward Euler on with = 0.01. What does each step do?
Show the solution
- One step.
- What it does to the fast mode. The fast mode is crushed by a factor of 11 every step instead of exploding.
- Compare the exact decay. That's slower than the exact decay, per step, but the mode is gone within a few steps either way, which is all that matters for a mode that has died out.
Answer each step divides by 11, so the fast mode is gone within a few steps.
Worked example
Apply the trapezoidal rule to with = 0.01. What does each step do?
Show the solution
- Write the step. The trapezoidal rule averages the slopes at both ends:
- Solve for .
- Read the factor. It's stable, since the factor is below 1 in size, but the sign flips every step: a slowly decaying oscillation that the true solution doesn't have.
- Compare backward Euler. Backward Euler gives per step, decaying smoothly. That's why simulators often take a few backward Euler steps after a sudden change before switching to the more accurate trapezoidal rule.
Answer each step multiplies by −0.667: stable, but the sign flips every step.
Check
A circuit's fastest time constant is 10 µs. What is the largest step forward Euler can take without blowing up?
Write units the way you normally would: 1.5 µs, 1500 ns and 0.0015 ms are the same answer.
Check
Backward Euler solves with = 2. By what factor does shrink each step?
Check
A circuit has time constants 1 µs and 1 s. You need to simulate 3 slow time constants. How many forward Euler steps, at the stability limit?
Check
Forward Euler solves with and = 3. What is after 5 steps?
Check
Why do circuit simulators like SPICE use implicit integration methods?
Check
Write backward_euler(A, x0, h, n), taking n backward Euler steps for and returning the final state. Factor or reuse ; don't recompute it inside the loop.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
is stepped with = 0.03.
(a)
What factor does forward Euler multiply by each step?
(b)
What factor does the trapezoidal rule multiply by?
Check
A circuit has time constants (fast) and (slow), both in seconds, and is simulated for .
Step 1
What is the largest stable forward Euler step?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
How many forward Euler steps does the run take?
Explain why
Why does the fastest time constant limit forward Euler's step size even after that mode has decayed away?
Forward Euler multiplies each mode by every step. Rounding errors and the tiny remnants of the fast mode never become exactly zero, so if , those remnants are amplified every step and eventually swamp the solution. The method has no way to know the mode is irrelevant; stability is decided by the eigenvalues, not by how much of each mode is present. Implicit methods have factors below 1 in size for every decaying mode, so the step size can be chosen for the slow behavior alone.
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.