---
title: Stiffness and implicit methods
heading: When a transient that ended long ago still dictates the step size
eyebrow: A13 · Lesson 43 · Stiffness and implicit methods
xp: 40
---

::: hook
Almost every real circuit has time constants spread over many decades: a 1 ms filter pole next to a parasitic capacitance that settles in a nanosecond. Such a system is **stiff**. The fast transient is over almost at once, and accuracy would allow big steps after that, but an explicit method like forward Euler or RK4 stays stable only if its step is comparable to the *fastest* time constant, for the whole simulation. Implicit methods remove that limit by solving an equation at each step, and they're why SPICE can simulate a microsecond switching converter for seconds.
:::

::: play
- The circuit has two decaying modes, $e^{-t/\tau_1}$ with $\tau_1$ = 1 µs and $e^{-t/1\text{ ms}}$. The black curve is exact; the stems at each step show forward Euler (orange) and backward Euler (dashed).
- With h below 2 µs, forward Euler tracks the slow decay. Push h past 2 µs: the 1 µs mode, long gone in the true solution, comes back with alternating sign and grows without bound.
- Backward Euler stays stable at any h, and its step can grow to the size the slow decay needs, about 50 µs here, for 50 times fewer steps.
:::
:::

```sim plot
view: graph
x: t = 0..3 ms
y: v = -1..2.2 V
slider: h = 0.0002..0.1 = 0.0015 log
plot: exp(-t) + exp(-t/0.001) | label: exact
plot: abs(1 - h)^floor(t/h) + abs(1 - h/0.001)^floor(t/h)*(1 - step(h/0.001 - 1)*(1 - cos(pi*floor(t/h)))) | samples: 1500 | color: ch2 | label: forward Euler
plot: (1/(1 + h))^floor(t/h) + (1/(1 + h/0.001))^floor(t/h) | samples: 1500 | dashed | color: ch3 | label: backward Euler
readout: step h, µs = h*1000
readout: forward Euler's fast-mode factor per step = 1 - h/0.001
readout: backward Euler's fast-mode factor per step = 1/(1 + h/0.001)
```

::: predict
## A circuit's fastest time constant is 1 ns and its slowest 1 ms. With forward Euler, about how many steps does a 10 ms simulation need at least?

- [ ] 10
- [ ] 10 000
- [x] 5 million
- [ ] 10 billion

::: reveal
At least 5 million: stability needs $h < 2\tau_{fast} = 2$ ns, and 10 ms / 2 ns = $5 \times 10^6$, though after the first few nanoseconds the solution only changes on a millisecond scale. An implicit method could take a few hundred steps.
:::
:::

::: nameit
## Stiffness

A system is stiff when its time constants span a large ratio $\tau_{slow}/\tau_{fast}$, and you care about behavior on the slow scale. Explicit methods' stability regions are bounded, so they need $h \lesssim \tau_{fast}$ (forward Euler: $h < 2\tau_{fast}$), however smooth the solution.

## Implicit methods

**Backward Euler** evaluates the slope at the new point:

$$y_{n+1} = y_n + h\,f(t_{n+1}, y_{n+1})$$

On $\dot y = \lambda y$ it multiplies by $G = \frac{1}{1 - h\lambda}$, below 1 in size for every $\text{Re}\,\lambda < 0$ and every h (**A-stable**), and tending to 0 for very fast modes (**L-stable**): stiff transients are simply wiped out.

| Method | G on $\dot y = \lambda y$ | Order | Stiff modes |
|---|---|---|---|
| backward Euler | $\frac{1}{1 - h\lambda}$ | 1 | damped to zero |
| trapezoidal | $\frac{1 + h\lambda/2}{1 - h\lambda/2}$ | 2 | $G \to -1$: they ring |
| BDF2 (Gear) | (two-step) | 2 | damped |
| SDIRK, Radau | (multistage) | 2 to 5 | damped |

## The cost

Each implicit step solves an equation for $y_{n+1}$: a linear system for a linear circuit, a Newton iteration (lesson 34) for a nonlinear one. In a circuit simulator, backward Euler turns each capacitor into a conductance $C/h$ in parallel with a current source $Cv_n/h$, its **companion model**, and each time step is a DC solve of the resulting circuit.

## Trapezoidal ringing

The trapezoidal rule is second-order and A-stable, so SPICE uses it by default, but for modes with $h \gg \tau$ its factor approaches −1: the fast mode flips sign each step and decays slowly, showing up as a sawtooth on node voltages. Switching to Gear's method (BDF2) removes it.
:::

::: example
## The play's circuit: compare forward Euler, backward Euler and the trapezoidal rule at h = 50 µs.

::: solution
1. **Forward Euler.** The 1 µs mode's factor is
   $$1 - 50 = -49$$
   so it explodes.
2. **Backward Euler.**
   $$\frac{1}{1 + 50} = 0.0196$$
   The mode is gone after one step, and 5 ms takes 100 steps instead of the 2500 that forward Euler would need at 2 µs.
3. **Trapezoidal rule.**
   $$\frac{1 - 25}{1 + 25} = -0.923$$
   Stable, but the fast mode alternates in sign and still has 45% of its size after 10 steps.

**Answer:** forward Euler explodes, backward Euler removes the fast mode in one step, and the trapezoidal rule stays stable but leaves the fast mode flipping sign, with 45% left after 10 steps.
:::
:::

::: example
## Write backward Euler's companion model for a 10 µF capacitor with a 1 µs step.

::: solution
1. **Discretize.**
   $$i = C\frac{v_{n+1} - v_n}{h}$$
2. **The conductance.**
   $$C/h = 10\ \text{S}$$
3. **The current source.** In parallel sits a source $Cv_n/h = 10v_n$ A, pointing to push current in the direction that keeps $v$ near $v_n$.
4. **Each step.** Each step then solves a resistive circuit.

**Answer:** a 10 S conductance in parallel with a $10v_n$ A current source.
:::
:::

::: example
## A fast mode has $h\lambda = -100$. What do backward Euler and the trapezoidal rule do to it in one step?

::: solution
1. **Backward Euler.**
   $$\begin{aligned} \frac{1}{1 - h\lambda} &= \frac{1}{101} \\ &= 0.0099 \end{aligned}$$
   One step nearly removes the mode, as the true solution would ($e^{-100}$).
2. **Trapezoidal rule.**
   $$\begin{aligned} \frac{1 + h\lambda/2}{1 - h\lambda/2} &= \frac{-49}{51} \\ &= -0.96 \end{aligned}$$
   The mode survives, flipping sign every step.
3. **A-stable and L-stable.** Both methods are stable for every step size (A-stable), but only backward Euler damps very fast modes strongly (L-stable).
4. **In simulators.** That's the source of the trapezoidal sawtooth on switching circuits, and why simulators switch to backward Euler for a step or two after each switching event.

**Answer:** backward Euler multiplies the mode by 0.0099, nearly removing it; the trapezoidal rule multiplies it by −0.96, so it survives and flips sign each step.
:::
:::

::: check
given: t = 1 | 10 | 100
answer: 2*t
unit: ns
tolerance: 0.5%

## A circuit's fastest time constant is {t} ns. Below what step must forward Euler stay?

::: right
Right. $2\tau$ = {answer} ns, however slow the rest of the circuit is.
:::

::: misses
- [t] At $h = \tau$ the mode jumps to zero in one step; instability begins at $2\tau$.
- [any] Not yet. $\lvert 1 - h/\tau\rvert \le 1$.
:::
:::

::: check
given: h = 10 | 50 | 1000; t = 1 | 3
answer: 1/(1 + h/t)
tolerance: 0.5%

## Backward Euler with step {h} µs on a mode with τ = {t} µs: by what factor is that mode multiplied each step?

::: right
Right. $\frac{1}{1 + h/\tau}$ = {answer}.
:::

::: misses
- [1 - h/t] That's forward Euler's factor.
- [any] Not yet. $G = \frac{1}{1 - h\lambda}$ with $\lambda = -1/\tau$.
:::
:::

::: check
given: h = 10 | 50 | 1000; t = 1 | 3
answer: (1 - h/(2*t))/(1 + h/(2*t))
tolerance: 0.5%

## And the trapezoidal rule's factor for that mode?

::: right
Right. $\frac{1 - h/2\tau}{1 + h/2\tau}$ = {answer}: close to −1 when $h \gg \tau$, the source of ringing.
:::

::: misses
- [1/(1 + h/t)] That's backward Euler's.
- [any] Not yet. $G = \frac{1 + h\lambda/2}{1 - h\lambda/2}$.
:::
:::

::: check
given: C = 1 | 10 | 100; h = 0.1 | 2 | 5
answer: C/h
unit: S
tolerance: 0.5%

## In a backward-Euler companion model, what conductance stands for a {C} µF capacitor with a {h} µs step?

::: right
Right. $C/h$ = {answer} S.
:::

::: misses
- [h/C] Conductance is $C/h$: a larger capacitor or a shorter step is a stiffer source.
- [any] Not yet. $i = C\frac{v_{n+1} - v_n}{h}$.
:::
:::

::: check
given: f = 0.000001 | 0.000000001; s = 0.001 | 1; T = 0.01 | 1
answer: T/(2*f)
tolerance: 0.5%

## A circuit's time constants run from {f} s to {s} s. At least how many forward-Euler steps does a {T} s simulation need?

::: right
Right. $T/(2\tau_{fast})$ = {answer}.
:::

::: misses
- [T/(2*s)] It's the fastest time constant that limits an explicit method.
- [any] Not yet. $h < 2\tau_{fast}$.
:::
:::

::: check
kind: choice

## A SPICE simulation of a switching converter shows a sawtooth on a node that should be smooth, flipping sign every time step. What's the likely cause and fix?

- [ ] Too large a tolerance; tighten reltol
- [x] Trapezoidal ringing on a fast mode; switch the integration method to Gear (BDF2)
- [ ] The circuit is unstable; add damping resistors
- [ ] Rounding error; use higher precision

::: misses
- [1] Tightening helps a little, but the trapezoidal rule doesn't damp stiff modes at any tolerance.
- [3] A real instability wouldn't alternate exactly with the time step.
- [4] It's the integration method, not rounding.
:::
:::

::: check
kind: parts
given: f = 1 | 10; s = 1 | 10; T = 0.1 | 1

## A circuit's fastest time constant is {f} µs and its slowest {s} ms. You simulate {T} s.

::: part
answer: T/(2*f*1e-6)
tolerance: 0.5%

### At least how many steps does forward Euler need, from its stability limit?

::: misses
- [T/(f*1e-6)] The limit is $h < 2\tau_\text{fast}$.
- [any] $T/(2\tau_\text{fast})$.
:::
:::

::: part
answer: 20*T/(s*1e-3)
tolerance: 0.5%

### How many does backward Euler need if accuracy asks for $h = \tau_\text{slow}/20$?

::: misses
- [any] $T/h$ with $h = \tau_\text{slow}/20$.
:::
:::
:::

::: check
kind: derivation
vars: y = -2..2, h = 0.001..0.1, l = -1000..-1, g = -1..1

## Backward Euler on $\dot y = \lambda(y - g)$, with g the value at the new time.

::: step
answer: (y - h*l*g)/(1 - h*l)

### Write λ as l. What is the new y?
:::

::: right
Right. For a stiff mode, $h\lambda$ is large and negative and the new y is pulled almost exactly to g, as the true solution would be.
:::
:::

::: explain
## Why can an implicit method take large steps on a stiff circuit when an explicit one can't?

::: model
For a mode that decays as $e^{\lambda t}$, an explicit method predicts the next value from the current slope, multiplying by something like $1 + h\lambda$. For a very fast mode, $h\lambda$ is a large negative number unless h is tiny, so the factor exceeds 1 in size and the mode, which should be gone, grows instead. An implicit method uses the slope at the end of the step, giving a factor like $\frac{1}{1 - h\lambda}$, which shrinks toward zero as $h\lambda$ grows more negative: large steps damp fast modes even harder. The step can then be chosen for accuracy on the slow behavior you care about, at the price of solving an equation each step.
:::
:::

::: practice

::: check
given: t = 0.1 | 0.5 | 1 | 2 | 5 | 20
answer: 2*t
unit: ns
tolerance: 0.5%

## Forward-Euler step limit for τ = {t} ns?

::: misses
- [any] $2\tau$.
:::
:::

::: check
given: h = 20 | 200; t = 2 | 0.5
answer: 1/(1 + h/t)
tolerance: 0.5%

## Backward-Euler factor, h = {h}, τ = {t}?

::: misses
- [any] $\frac{1}{1 + h/\tau}$.
:::
:::

::: check
given: C = 4.7 | 220; h = 0.5 | 5
answer: C/h
unit: S
tolerance: 0.5%

## Companion conductance, {C} µF, {h} µs?

::: misses
- [any] $C/h$.
:::
:::
:::
