Root finding, step by step
Bisection, Newton, secant and fixed-point iteration side by side, one step per click, with tangents, secants, a cobweb diagram, an iterate table and a log error plot; Newton's failures (flat tangents, cycles, divergence), basins of attraction, the complex z³ − 1 fractal, and Babylonian square roots digit by digit.
Added
How to use it
Type a function f(x) — x^2 - 2, cos(x) - x, x^3 - 2x + 2, atan(x) — and watch four ways of
solving f(x) = 0 race each other. Everything runs in double precision, exactly as the book’s
Python does, so the numbers agree digit for digit.
⛶ Full screen (or F) gives the open tab’s picture the whole screen — the four method plots,
the Newton curve (with its basin strip above it), the complex-basin fractal or the Babylonian
square — using the browser’s full screen where it is allowed, otherwise a full-window layer
(iPhone). Everything is redrawn at the new size; Escape leaves.
Side by side
Set a bracket [a, b] (where f changes sign), a starting value x₀ and, for fixed-point iteration, a rearrangement x = g(x). Step ▶ takes one step with every method:
-
Bisection shades the bracket and marks the midpoint with the sign of f(m).
-
Newton follows the tangent at xₙ down to the axis. Type f′(x) for exact tangents; leave it blank and a numerical derivative is used.
-
Secant starts from a and b and follows the line through the last two points.
-
Fixed point draws the cobweb: up to y = g(x), across to y = x, and again.
The error plot shows |xₙ − root| on a log scale (bisection’s straight line, Newton’s plunge,
the secant’s golden-ratio order 1.618, fixed point’s constant ratio |g′(r)|), and reports the
first step at which each method gets below the tolerance (10⁻¹² unless the link sets tol). The
table lists every iterate; pick one method to see its full table — a, b, m and f(m) for
bisection; xₙ, f(xₙ), f′(xₙ) and the correction for Newton; the error ratio for fixed point.
Newton explorer
Drag x₀ (or click the curve) and see where Newton’s method goes, with each tangent drawn and a table of xₙ, f(xₙ), f′(xₙ) and the correction. The verdict says whether it converges, cycles, diverges, stops at a horizontal tangent, or wanders. The colour strip under the graph colours every starting value in view by the root it reaches — zoom in on x³ − x near ±0.447 to see the bands interleave. Animate replays the tangents one at a time; race bisection adds bisection on [a, b] to the error plot. For arctan x the page prints the exact divergence threshold, x₀ ≈ 1.3917452, where Newton bounces between x₀ and −x₀ for ever.
Complex basins
Newton’s method works unchanged on complex numbers. Every pixel is a starting value z₀, coloured by the root of z³ − 1 it reaches (darker: more steps). Click to zoom in ×2. Try z³ − 2z + 2 to see black islands of starting points trapped in the same 0 ↔ 1 cycle as on the real line.
Square roots
The Babylonian (Heron’s) method: average your guess g with a/g. Drag the side of a square until its area matches a, then step: g and a/g close in on √a from opposite sides, and the table shows the correct digits of each guess in green — 1, 3, 6, 12, then all 16 a double can hold.
Limits
-
Everything is IEEE double precision (about 16 significant digits); errors are measured against roots found to the last bit, so they bottom out near 10⁻¹⁶ and are drawn at 10⁻¹⁷ when exactly zero.
-
The numerical derivative (when f′ is blank) is a 5-point central difference, accurate to about 12 digits for smooth f; Newton then still converges, but the last digits are not quadratic.
-
Roots for the error plots are found by scanning [−20, 20] (wider when your inputs are), so a root far outside that range may be missed.
-
Steps are capped at 60 (side by side) and 100 (explorer).
Related: Graphing calculator (roots, extrema, intersections), Where floating point bites (cancellation, the V-shaped error of numerical derivatives), Algebra step by step (the quadratic formula, factoring), Symbolic algebra (exact derivatives to paste into f′).
Companion to Mathematics, Reconnected: Powers and roots (the root finder), Quadratics (bisection versus Newton), Limits (the bisection stepper, Heron’s method), Applications of derivatives (Newton’s method explorer) and Numerical methods (root finding compared, Newton’s basins).
Linking to an example
Every setting can be written by hand in the address, so a link can open an exact state, for
example /tools/root-finding/?f=x^3-2x%2B2&x0=0&n=6#newton. The part after # picks the tab:
#steps, #newton, #fractal or #sqrt. Settings a link leaves out take their defaults.
Write ` in an expression as `%2B` to be safe. A bare ` also works: a URL turns it into a
space, and the tool reads a space between two terms as plus (x^2+1 → x^2 1 → x^2+1).
Write products without spaces (2x, 2*x).
| Parameter | Meaning | Example |
|---|---|---|
|
the function whose root is wanted |
|
|
its derivative for Newton (blank: numerical) |
|
|
fixed-point rearrangement x = g(x) |
|
|
bisection bracket; the secant method starts from a and b (numbers or expressions) |
|
|
Newton’s and fixed-point iteration’s start |
|
|
steps already taken (0–60) |
|
|
side-by-side focus: |
|
|
tolerance for the "first step below" race |
|
|
graph view (blank: automatic) |
|
|
add bisection on [a, b] to the Newton explorer’s error plot |
|
|
complex basins: |
|
|
complex basins: view centre and width |
|
|
complex basins: maximum Newton steps per pixel |
|
|
square roots: the number a in √a |
|
|
square roots: the first guess |
|
|
square roots: Babylonian steps taken |
|
|
a book example (below); its settings win over any given beside it |
|
Book examples, as ?example=<name> (the tab is chosen for you):
| Name | Tab | Shows |
|---|---|---|
|
sqrt |
Root finder: √20 by the Babylonian method |
|
sqrt |
Exercise: two Babylonian steps for √50 from 7 |
|
steps |
Bisection on x² − 2x − 1 over [2, 3]: 40 halvings |
|
steps |
Bisection versus Newton on x² − 2 |
|
newton |
Newton started exactly at the vertex: horizontal tangent |
|
newton |
Newton on x² + 1 wanders chaotically |
|
steps |
Bisection on x³ − x − 2 over [1, 2] (the hand table) |
|
steps |
Bisection stepper |
|
steps |
Bisection on 1/x over [−1, 2] "converges" to the asymptote |
|
steps |
cos x = x on [0, π/2]: three bisection steps |
|
sqrt |
Heron’s method for √2 from 1 |
|
steps |
Newton (from 1) versus bisection (on [1, 2]) for √2 |
|
newton |
Newton’s own cubic x³ − 2x − 5 from 2 |
|
newton |
x³ − 2x + 2 from 0 cycles 0, 1, 0, 1, … |
|
newton |
arctan x from 1.5 diverges; the threshold is near 1.39 |
|
newton |
∛x: every Newton step doubles the distance |
|
newton |
x² − 2 from 0.01: a near-flat tangent throws x₁ to 100 |
|
newton |
x³ − x: interleaved basins near ±0.447 |
|
newton |
x³ − x: zoom into the bands near 0.447 |
|
steps |
(x − 1)²: a double root makes Newton merely linear |
|
newton |
Newton’s method explorer |
|
fractal |
Newton basins for z³ − 1 in the complex plane |
|
steps |
Bisection, Newton, secant and fixed point on x² − 2 |
|
steps |
The secant method from 1 and 2 |
|
steps |
Fixed point x ← x − (x² − 2)/3: ratio 0.057 |
|
steps |
Fixed point x ← 2/x oscillates 1, 2, 1, 2 |
|
newton |
Newton’s basins: x³ − 2x + 2 |
|
fractal |
Fractal basins for z³ − 1 |
|
fractal |
z³ − 2z + 2: black islands that never converge |
Feedback is a gift. Something to improve, a feature to add, or a bug? Tell me.
Runs entirely in your browser; nothing you type leaves this page.