A846 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 1090: 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 y˙=−y (time constant 1) with step size h. The smooth curve is the exact e−t.
  • Explicit (forward) Euler multiplies by 1−h each step; implicit (backward) Euler divides by 1+h.
  • Push h past 1, then past 2. What happens to each?

Predict

Forward Euler on y˙=−1000y with h = 0.01. What happens?

Name it

Stability of a method

Apply a method to the test equation y˙=λy (λ<0). Each step multiplies y by a factor R(hλ); the method is stable when |R|≤1.

MethodStepFactor RStable for
forward (explicit) Euleryn+1=yn+hf(yn)1+hλh≤2|λ|
backward (implicit) Euleryn+1=yn+hf(yn+1)11−hλevery h>0
trapezoidalaverage of the two1+hλ/21−hλ/2every h>0

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 5 s2 µs=2.5 million steps.

Implicit methods

Backward Euler for 𝐱˙=A𝐱 needs a solve at every step:

(I−hA)𝐱n+1=𝐱n

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 I−hA 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
  1. Forward Euler's step limit. Stability needs h≤2×1 µs =2 µs.
  2. Count the steps. 52×10−6=2.5×106 steps, all to resolve a mode that dies in the first few microseconds.
  3. Compare backward Euler. Backward Euler with h = 10 ms, accurate enough for the 1 s mode, needs 500.

Answer forward Euler takes 2.5×106 steps; backward Euler needs only 500.

Worked example

Backward Euler on y˙=−1000y with h = 0.01. What does each step do?

Show the solution
  1. One step. yn+1=yn1+10=yn11
  2. What it does to the fast mode. The fast mode is crushed by a factor of 11 every step instead of exploding.
  3. Compare the exact decay. That's slower than the exact decay, e−10 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 y by 11, so the fast mode is gone within a few steps.

Worked example

Apply the trapezoidal rule to y˙=−1000y with h = 0.01. What does each step do?

Show the solution
  1. Write the step. The trapezoidal rule averages the slopes at both ends: yn+1=yn−5(yn+yn+1)
  2. Solve for yn+1. yn+1=1−51+5yn=−0.667yn
  3. 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.
  4. Compare backward Euler. Backward Euler gives 111=0.091 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 y 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 y˙=−y with h = 2. By what factor does y 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 y˙=−y with y(0)=1 and h = 3. What is y 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 𝐱˙=A𝐱 and returning the final state. Factor or reuse I−hA; 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

y˙=−100y is stepped with h = 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 f (fast) and T (slow), both in seconds, and is simulated for 5T.

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°.

Explain why

Why does the fastest time constant limit forward Euler's step size even after that mode has decayed away?

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.