---
title: Bisection and fixed-point iteration
heading: Two slow, simple ways to solve f(x) = 0, and when each works
eyebrow: A13 · Lesson 4 · Bisection and fixed-point iteration
xp: 40
---

::: hook
A diode in series with a resistor: the current depends on the diode's voltage, the voltage depends on the current through an exponential, and no algebra untangles them. Equations like that, $f(x) = 0$ with no formula for x, are everywhere in circuits, from a bias point to the frequency where a gain crosses 1. The two simplest ways to solve them are **bisection**, which can't fail once you've bracketed a root but gains only one bit per step, and **fixed-point iteration**, which rewrites the equation as $x = g(x)$ and repeats. Whether the second converges, and how fast, comes down to a single number: the slope of g at the answer.
:::

::: play
- The orange dots are iterates of $x_{n+1} = a\cos x_n$: each dot sits on the curve at $(x_n, x_{n+1})$, and the dots on the dashed line $y = x$ mark where the next step starts. Read them alternately to trace the cobweb.
- With a = 1 the iterates spiral in to 0.739, where $\cos x = x$. The slope there is −0.67, so each step cuts the error by about a third and flips its sign.
- Raise a past about 1.32: the slope at the fixed point passes −1, and the iterates spiral outward instead. The fixed point is still there; iteration just can't reach it.
:::
:::

```sim plot
view: graph
x: x = 0..3
y: y = -1..3
slider: a = 0.5..2 step 0.01 = 1
slider: x0 = 0..3 step 0.01 = 2.5
plot: a*cos(x) | label: g(x) = a cos x
plot: x | dashed | label: y = x
point: x0, a*cos(x0) | label: x₀
point: a*cos(x0), a*cos(a*cos(x0))
point: a*cos(a*cos(x0)), a*cos(a*cos(a*cos(x0)))
point: a*cos(a*cos(a*cos(x0))), a*cos(a*cos(a*cos(a*cos(x0))))
point: a*cos(a*cos(a*cos(a*cos(x0)))), a*cos(a*cos(a*cos(a*cos(a*cos(x0)))))
point: a*cos(a*cos(a*cos(a*cos(a*cos(x0))))), a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0))))))
point: a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0)))))), a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0)))))))
point: a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0))))))), a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0))))))))
point: a*cos(x0), a*cos(x0) | color: ch3
point: a*cos(a*cos(x0)), a*cos(a*cos(x0)) | color: ch3
point: a*cos(a*cos(a*cos(x0))), a*cos(a*cos(a*cos(x0))) | color: ch3
point: a*cos(a*cos(a*cos(a*cos(x0)))), a*cos(a*cos(a*cos(a*cos(x0)))) | color: ch3
point: a*cos(a*cos(a*cos(a*cos(a*cos(x0))))), a*cos(a*cos(a*cos(a*cos(a*cos(x0))))) | color: ch3
point: a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0)))))), a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0)))))) | color: ch3
point: a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0))))))), a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0))))))) | color: ch3
point: a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0)))))))), a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0)))))))) | color: ch3
readout: x₈ = a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0))))))))
readout: |g′| at x₈ = abs(a*sin(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(a*cos(x0))))))))))
```

::: predict
## Bisection starts with a root bracketed in [0, 2]. How many halvings guarantee the midpoint is within $10^{-6}$ of it?

- [ ] 6
- [ ] 14
- [x] 20
- [ ] 1 000 000

::: reveal
20: after n halvings the bracket is $2/2^n$ wide and its midpoint is within half of that, $2/2^{n+1}$, of the root. That's below $10^{-6}$ once $2^{n+1} \ge 2 \times 10^6$, at n = 20. Each step buys one bit, about 0.3 decimal digits, no matter how nice f is.
:::
:::

::: nameit
## Bisection

If f is continuous and $f(a)$, $f(b)$ have opposite signs, there's a root between them. Evaluate f at the midpoint m and keep the half whose ends still differ in sign. After n steps the midpoint is within

$$\lvert x_n - x^*\rvert \le \frac{b - a}{2^{n+1}}$$

so reaching a tolerance δ takes $n \ge \log_2\frac{b - a}{\delta} - 1$ steps. In double, about 52 halvings exhaust the bits of a bracket of width 1.

## Fixed-point iteration

Rewrite $f(x) = 0$ as $x = g(x)$ and iterate $x_{n+1} = g(x_n)$. Near the fixed point $x^*$,

$$e_{n+1} = x_{n+1} - x^* = g(x_n) - g(x^*) \approx g'(x^*)\,e_n$$

- If $\lvert g'(x^*)\rvert < 1$, it converges **linearly**: each step multiplies the error by about $\rho = \lvert g'(x^*)\rvert$, gaining $\log_{10}(1/\rho)$ digits.
- If $g' > 0$ the iterates approach from one side; if $g' < 0$ they alternate sides (the spiral).
- If $\lvert g'(x^*)\rvert > 1$, it diverges from the fixed point, however close it starts.

The same equation can be rewritten many ways, and the choice of g decides everything. Lesson 6 picks the best possible one, with $g'(x^*) = 0$: Newton's method.

## When to stop

Stop when the step $\lvert x_{n+1} - x_n\rvert$ is below a tolerance, with a cap on the number of steps. For a linear rate ρ the remaining error is about $\frac{\rho}{1 - \rho}$ times the last step, which is large when ρ is near 1.
:::

::: example
## A 5 V source drives a diode ($I_s = 10^{-14}$ A, $nV_T$ = 25.85 mV) through 1 kΩ. Solve for the diode voltage by iterating $V_D \leftarrow nV_T\ln\left(\frac{(5 - V_D)/R}{I_s} + 1\right)$ from 0.7 V.

::: solution
1. **Iterate from 0.7 V.** The iterates are 0.692445, 0.692491 and 0.692490 V: settled to six digits in three steps.
2. **Why it's fast.**
   $$g'(V_D) = -\frac{nV_T}{5 - V_D} \approx -0.006$$
   so each step gains more than two digits.
3. **The other rearrangement.** It iterates
   $$V_D \leftarrow 5 - RI_s(e^{V_D/nV_T} - 1)$$
   with $\lvert g'\rvert = R\,I/nV_T \approx 167$, so it blows up at once.

**Answer:** $V_D$ = 0.692490 V, settled to six digits in three steps.
:::
:::

::: example
## Iterate $x \leftarrow \cos x$ from 1. How fast does it converge?

::: solution
1. **The rate at the fixed point.** The fixed point is 0.739085, where
   $$\begin{aligned} g'(x^*) &= -\sin 0.739085 \\ &= -0.674 \end{aligned}$$
2. **What each step does.** Each step multiplies the error by 0.674 and flips its sign, gaining
   $$\log_{10}(1/0.674) = 0.17$$
   digits.
3. **Steps for full precision.** At that rate, 15 digits take about 90 steps.

**Answer:** linearly, to 0.739085, gaining 0.17 digits a step: about 90 steps for 15 digits.
:::
:::

::: example
## Solve Kepler's equation $E = M + e\sin E$ for e = 0.5 and M = 1 by fixed-point iteration.

::: solution
1. **Iterate.** Run $E \leftarrow 1 + 0.5\sin E$ from E = 1: 1.420735, 1.494381, 1.498541, 1.498695, 1.498701. The limit is 1.4987011.
2. **The rate.** At the root
   $$\begin{aligned} \lvert g'(E)\rvert &= 0.5\lvert\cos E\rvert \\ &= 0.036 \end{aligned}$$
   so each step gains about $-\log_{10}0.036 = 1.4$ digits.
3. **When it works.** Since $\lvert g'\rvert \le e < 1$ everywhere, the iteration converges from any start for every orbit with e < 1. For nearly parabolic orbits, e close to 1, it slows down and Newton's method is better.

**Answer:** E = 1.4987011, with each step gaining about 1.4 digits.
:::
:::

::: check
given: W = 1 | 2 | 10; d = 0.001 | 0.000001 | 0.000000001
answer: ceil(ln(W/d)/ln(2) - 1)
tolerance: 0

## A root is bracketed in an interval {W} wide. How many bisection steps guarantee the midpoint is within {d} of it?

::: right
Right. The smallest n with $W/2^{n+1} \le \delta$: {answer}.
:::

::: misses
- [ceil(ln(W/d)/ln(2))] The midpoint is within half the bracket, which saves one step.
- [any] Not yet. Solve $W/2^{n+1} \le \delta$ for whole n.
:::
:::

::: check
given: W = 4 | 1; n = 10 | 30
answer: W/2^(n + 1)
tolerance: 0.5%

## After {n} bisection steps on a bracket {W} wide, what's the worst-case error of the midpoint?

::: right
Right. $W/2^{n+1}$ = {answer}.
:::

::: misses
- [W/2^n] That's the bracket's width; the midpoint is within half of it.
- [any] Not yet. $\frac{W}{2^{n+1}}$.
:::
:::

::: check
given: c = 1 | 2 | 3
answer: 1/((c + sqrt(c^2 + 4))/2)^2
tolerance: 0.5%

## The iteration $x \leftarrow \given{c} + 1/x$ converges to the positive root of $x^2 - \given{c}x - 1 = 0$. By what factor does each step shrink the error?

::: right
Right. $\lvert g'(x^*)\rvert = 1/x^{*2}$ = {answer}, with the sign alternating.
:::

::: misses
- [1/((c + sqrt(c^2 + 4))/2)] $g'(x) = -1/x^2$: square the fixed point.
- [any] Not yet. Find $x^* = \frac{c + \sqrt{c^2 + 4}}{2}$ and evaluate $\lvert g'\rvert$ there.
:::
:::

::: check
given: r = 0.5 | 0.1 | 0.9; d = 6 | 12
answer: d/log(1/r)
tolerance: 1%

## A linearly convergent iteration has rate ρ = {r}. About how many steps does it take to gain {d} decimal digits?

::: right
Right. $d/\log_{10}(1/\rho)$ = {answer} steps.
:::

::: misses
- [d/ln(1/r)] Digits are decimal: use $\log_{10}$.
- [any] Not yet. Each step gains $\log_{10}(1/\rho)$ digits.
:::
:::

::: check
given: V = 3.3 | 5 | 12; R = 470 | 1000 | 10000
answer: 0.02585*ln((V - 0.7)/R/1e-14 + 1)
unit: V
tolerance: 0.1%

## A {V} V source drives a diode ($I_s = 10^{-14}$ A, $nV_T$ = 25.85 mV) through {R} Ω. What's $V_D$ after one fixed-point step from 0.7 V?

::: right
Right. $nV_T\ln\left(\frac{(V - 0.7)/R}{I_s} + 1\right)$ = {answer} V.
:::

::: misses
- [0.02585*log((V - 0.7)/R/1e-14 + 1)] The diode law uses the natural logarithm.
- [any] Not yet. Current from the guess, then the diode voltage for that current.
:::
:::

::: check
kind: choice

## Which rearrangement of $x^2 = 2$ converges fastest to $\sqrt2$ by fixed-point iteration?

- [ ] $x \leftarrow 2/x$
- [ ] $x \leftarrow x - (x^2 - 2)$
- [x] $x \leftarrow \frac12\left(x + \frac2x\right)$
- [ ] $x \leftarrow x^2 + x - 2$

::: misses
- [1] $g' = -2/x^2 = -1$ at $\sqrt2$: it bounces between two values forever.
- [2] $g' = 1 - 2\sqrt2 \approx -1.83$: it diverges.
- [4] $g' = 2\sqrt2 + 1$: it diverges.
:::
:::

::: check
kind: parts
given: e = 0.1 | 0.5; M = 1 | 2

## Kepler's equation $E = M + e\sin E$ is solved by $E \leftarrow \given{M} + \given{e}\sin E$ from $E_0 = M$.

::: part
answer: M + e*sin(M)
tolerance: 0.5%

### What is $E_1$?

::: misses
- [M + e*sin(M*pi/180)] Angles are in radians.
- [any] One step of the iteration.
:::
:::

::: part
answer: ceil(6/log(1/e))
tolerance: 0

### Using the bound $\lvert g'\rvert \le e$, at most how many steps gain 6 digits?

::: misses
- [any] Each step gains at least $-\log_{10}e$ digits.
:::
:::
:::

::: check
kind: derivation
vars: a = 1..10, c = 0.05..0.3

## The iteration $x \leftarrow g(x) = x - c(x^2 - a)$ seeks $\sqrt a$.

::: step
answer: 1 - 2*c*sqrt(a)

### What is $g'(\sqrt a)$?
:::

::: step
answer: 1/(2*sqrt(a))

### Which c makes $g'(\sqrt a) = 0$, for the fastest convergence?
:::

::: right
Right. With that c the iteration becomes quadratic near the root: it's Newton's method with the derivative frozen at the answer.
:::
:::

::: explain
## Why does fixed-point iteration converge when $\lvert g'(x^*)\rvert < 1$ and fail when it's greater?

::: model
Near the fixed point, g is almost a straight line through $(x^*, x^*)$ with slope $g'(x^*)$. If the current guess is off by e, the next guess is off by about $g'(x^*)\,e$, because g maps the small interval around $x^*$ onto an interval $\lvert g'\rvert$ times as wide. With $\lvert g'\rvert < 1$ every step shrinks the error by that factor, so the iterates close in geometrically; with $\lvert g'\rvert > 1$ every step stretches it, so even a guess very near $x^*$ is pushed away. The sign of $g'$ only decides whether the iterates approach from one side or alternate around the fixed point.
:::
:::

::: practice

::: check
given: W = 3 | 0.5; d = 0.0001 | 0.0000001
answer: ceil(ln(W/d)/ln(2) - 1)
tolerance: 0

## Bisection steps, bracket {W}, tolerance {d}?

::: misses
- [any] Smallest n with $W/2^{n+1} \le \delta$.
:::
:::

::: check
given: r = 0.3 | 0.99; d = 8 | 10
answer: d/log(1/r)
tolerance: 1%

## Steps to gain {d} digits at rate {r}?

::: misses
- [any] $d/\log_{10}(1/\rho)$.
:::
:::

::: check
given: c = 0.5 | 1 | 2 | 3 | 4 | 6
answer: 1/((c + sqrt(c^2 + 4))/2)^2
tolerance: 0.5%

## Error factor for $x \leftarrow \given{c} + 1/x$?

::: misses
- [any] $1/x^{*2}$.
:::
:::
:::
