Numerical Methods · Learn

Root Finding

How to solve $f(x)=0$ when no formula exists — by guessing, then improving. Three classic methods, why one rearrangement converges while another explodes, and how fast each one closes in.

▶ Play the lab 📖 Learn the theory

1The problem

Find the root $x^*$ where $f(x^*)=0$. A few equations factor nicely; most — $\cos x = x$, $x e^x = 1$, a pressure-drop correlation — don't. So we build a sequence of guesses $x_0, x_1, x_2,\dots$ from a rule that drives them toward the root, and stop when successive guesses barely move. The questions that matter: does it converge, and how fast?

2Fixed-point iteration

Rewrite $f(x)=0$ algebraically as $x = g(x)$. A root is now a fixed point — a value the map $g$ leaves unchanged. Iterate it:

$$ x_{n+1} = g(x_n) $$

Geometrically, a fixed point is where $y=g(x)$ meets the diagonal $y=x$. The iteration draws a cobweb: up to the curve, across to the diagonal, repeat. Whether it spirals in or staircases out depends entirely on the slope of $g$ at the root:

$$ \text{converges} \iff |g'(x^*)| < 1 $$

If $g$ is flatter than the diagonal there, errors shrink each step; if steeper, they grow. The convergence is linear — the error multiplies by roughly $|g'(x^*)|$ each iteration.

The classic surprise · $x^3 - x - 1 = 0$

This has a single real root, $x^*\approx 1.3247$. Rearrange it three different ways — all algebraically identical — and watch their fates diverge:

Rearrangement $g(x)$$|g'(x^*)|$Result
$x = x^3 - 1$≈ 5.3diverges
$x = (x+1)^{1/3}$≈ 0.19converges
$x = 1/(x^2-1)$≈ 4.6diverges

Same equation, opposite outcomes — the rearrangement is everything. There's no guarantee any given $g$ works; part of the craft is finding one that does.

▶ In the lab

Switch between these three with the preset chips and watch the cobweb spiral in or staircase to infinity, with the live $|g'|$ readout telling you which side of 1 you're on. Open the lab →

3Newton's method

Don't guess a rearrangement — use the function's own slope. Stand at $x_n$, follow the tangent line down to where it crosses the axis, and land at $x_{n+1}$:

$$ x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} $$

Newton's method is famously fast: near a simple root the number of correct digits roughly doubles every stepquadratic convergence. The price: you need the derivative, and a poor starting guess can send it wandering. (At a flat spot, $f'\to 0$, the tangent is nearly horizontal and the step blows up.)

Recipe

  1. Pick a starting guess $x_0$ near the root.
  2. Step with $x_{n+1}=x_n-f(x_n)/f'(x_n)$.
  3. Stop when $|x_{n+1}-x_n|$ is below tolerance.

4The secant method

What if you don't have $f'$? Replace the tangent with the line through your last two points — a finite-difference stand-in for the derivative:

$$ x_{n+1} = x_n - f(x_n)\,\frac{x_n - x_{n-1}}{f(x_n) - f(x_{n-1})} $$

No derivative needed, and only one new function evaluation per step. Its convergence order is the golden ratio $\varphi\approx 1.618$ — slower than Newton but often cheaper overall, which is why it's a workhorse in practice.

5Which method, when?

MethodNeedsSpeedWatch out for
Fixed-pointa good $g(x)$linear$|g'|\ge 1$ → diverges
Newton$f$ and $f'$quadratic$f'\approx 0$, bad start
Secant$f$ only≈1.6 (superlinear)nearly equal $f$ values

In the lab, derivatives for Newton are estimated numerically, so you only ever type the function itself.

Key takeaways

EngineeringCandy · Learn · the theory behind the playground