Calculus · Applications of derivatives

Finding Roots Numerically: Chords, Tangents and Iteration

There is no formula for the root of \(x^3 + x - 1 = 0\) that a student would want to use, and none at all for \(x = \cos x\). Yet a calculator finds both in a fraction of a second. How? By starting from a rough guess and improving it step by step. This post presents the classical methods for that (chords, tangents, iteration, plus the graphical method and bisection), explains why they work, and shows how fast each one converges.

1. Step zero: isolate the root

Every method below starts from an interval \([a, b]\) that contains exactly one root of

\[ f(x) = 0. \tag{1} \]
Isolating a root If \(f(x)\) is continuous on \([a, b]\), \( f(a)\,f(b) < 0 \), and \( f'(x) \ne 0 \) for \(x \in (a, b)\), then equation (1) has one and only one root \(\xi\) in \((a, b)\).

Why: \( f(a)f(b) < 0 \) means \(f\) changes sign, so by continuity it crosses zero at least once (the intermediate value theorem). And \(f' \ne 0\) means \(f\) is strictly monotone (post on extrema), so it can cross zero at most once.

Throughout the post we use one running example, from the post on mean value theorems:

Running example \( f(x) = x^3 + x - 1 \) on \([0, 1]\): \( f(0) = -1 < 0 \), \( f(1) = 1 > 0 \), and \( f'(x) = 3x^2 + 1 > 0 \). So there is exactly one root in \((0, 1)\). (To 10 digits, \( \xi = 0.6823278038 \).)

2. The simplest method: bisection

Before the classical methods, the simplest one of all: halve the interval, keep the half where \(f\) changes sign, repeat. After \(n\) steps the root is trapped in an interval of length \( \frac{b - a}{2^n} \).

Step123456
Interval[0.5, 1][0.5, 0.75][0.625, 0.75][0.625, 0.6875][0.65625, 0.6875][0.671875, 0.6875]

Bisection always works (it needs only continuity and a sign change) but is slow: each step gains one binary digit, so about 3.3 steps per decimal digit. The methods that use the derivative are much faster.

3. The method of chords (secant method)

Idea: replace the curve on \([a, b]\) by the straight line (chord) through \( A(a, f(a)) \) and \( B(b, f(b)) \), and take the point where the chord crosses the \(x\)-axis as the new approximation.

Method of chords Under the conditions of Section 1, the first approximation of the root is \( \alpha_1 = a + \varepsilon_1 \), where \[ \varepsilon_1 = -\frac{f(a)}{f(b) - f(a)}\,(b - a). \] Then apply the same procedure to the interval \((a, \alpha_1)\) or \((\alpha_1, b)\), depending on whether \( f(a)f(\alpha_1) < 0 \) or \( f(\alpha_1)f(b) < 0 \), to get the second approximation \(\alpha_2\), and so on.

Where the formula comes from: the chord has slope \( \frac{f(b) - f(a)}{b - a} \). Starting at height \(f(a)\) and moving \(\varepsilon_1\) to the right, it reaches zero when \( f(a) + \frac{f(b) - f(a)}{b - a}\varepsilon_1 = 0 \). Solving for \(\varepsilon_1\) gives the formula. The method is also known as regula falsi ("rule of false position"): it pretends, falsely, that the function is linear between the two points.

Example 1 · Chords for \(x^3 + x - 1 = 0\) Step 1: \( \varepsilon_1 = -\frac{-1}{1 - (-1)}\cdot 1 = 0.5 \), so \( \alpha_1 = 0.5 \), and \( f(0.5) = -0.375 < 0 \). The sign change is now on \((0.5, 1)\). Repeating:
\(n\)\(\alpha_n\)\(f(\alpha_n)\)actual error
10.5−0.3750.18
20.6363636−0.10593540.046
30.6711957−0.02642830.011
40.6796616−0.00637550.0027
50.6816910−0.00152540.00064
60.6821758−0.00036420.00015
The approximations all approach the root from the left, and the right endpoint \(b = 1\) never moves. The error shrinks by a roughly constant factor (about \(4\)) per step.

Error estimate

How do we know the error without knowing \(\xi\)? By Lagrange's theorem, \( f(\alpha_n) = f(\alpha_n) - f(\xi) = f'(c)(\alpha_n - \xi) \), so

\[ |\alpha_n - \xi| \le \frac{|f(\alpha_n)|}{m}, \qquad m = \min_{[a, b]}|f'(x)|. \]

In the example \( f'(x) = 3x^2 + 1 \ge 1 \), so \( m = 1 \): after step 6 the error is at most \( 0.00036 \). (Actually it is \(0.00015\); the estimate is honest but cautious.)

4. The method of tangents (Newton's method)

Idea: instead of the chord, follow the tangent at one end point down to the \(x\)-axis. Near the root the tangent is an excellent approximation of the curve (post on the differential), so this should be much more accurate.

Newton's method If \( f''(x) \ne 0 \) on \([a, b]\) and \( f(a)\,f''(a) > 0 \), then the first approximation of the root \(\xi\) of equation (1) can be taken as \[ \beta_1 = a - \frac{f(a)}{f'(a)}. \] Repeating the procedure gives after the \(n\)-th step the approximation \(\beta_n\): \[ \beta_{n+1} = \beta_n - \frac{f(\beta_n)}{f'(\beta_n)} \qquad (n = 1, 2, \dots). \]

Where the formula comes from: the tangent at \( (a, f(a)) \) is \( Y - f(a) = f'(a)(X - a) \) (post on tangents). Setting \(Y = 0\) gives exactly \( X = a - \frac{f(a)}{f'(a)} \). In the post on tangents this was the subtangent: Newton's step moves exactly one subtangent towards the root.

Which end to start from? Here \(a\) stands for whichever endpoint satisfies \( f(a)f''(a) > 0 \) (Fourier's condition): the end where the curve bends towards the axis. From that end the tangent always meets the axis between the root and the starting point, so all the approximations stay inside the interval and approach the root monotonically. From the other end the first tangent may overshoot far outside the interval.

x y A(0, −1) B(1, 1) α₁ β₁ ξ 1 chord tangent y = x³ + x − 1
Figure 1. One step of each method for \( f(x) = x^3 + x - 1 \) on \([0, 1]\). The chord \(AB\) (red) gives \(\alpha_1 = 0.5\), left of the root \(\xi\). The tangent at \(B\) (green), where \(f(1)f''(1) = 6 > 0\), gives \(\beta_1 = 0.75\), right of it. The two methods approach \(\xi\) from opposite sides.
Example 2 · Newton for \(x^3 + x - 1 = 0\) Here \( f''(x) = 6x \), and at \(b = 1\): \( f(1)f''(1) = 1\cdot 6 > 0 \). So start from \(1\): \[ \beta_{n+1} = \beta_n - \frac{\beta_n^3 + \beta_n - 1}{3\beta_n^2 + 1}. \]
\(n\)\(\beta_n\)actual error
10.756.8 · 10⁻²
20.68604653.7 · 10⁻³
30.68233961.2 · 10⁻⁵
40.68232780391.2 · 10⁻¹⁰
Four steps give ten correct digits. The chord method had barely four after six steps.

Why Newton is so fast

By Taylor's formula (previous post), expanding \(f\) around \(\beta_n\) at the root:

\[ 0 = f(\xi) = f(\beta_n) + f'(\beta_n)(\xi - \beta_n) + \frac{f''(c)}{2}(\xi - \beta_n)^2. \]

Dividing by \(f'(\beta_n)\) and using the definition of \(\beta_{n+1}\):

\[ \xi - \beta_{n+1} = -\frac{f''(c)}{2f'(\beta_n)}(\xi - \beta_n)^2, \qquad\text{so}\qquad |\xi - \beta_{n+1}| \le \frac{M}{2m}|\xi - \beta_n|^2, \]

with \( M = \max|f''| \), \( m = \min|f'| \). The new error is proportional to the square of the old one: quadratic convergence. Once the error is small, the number of correct digits roughly doubles at every step, exactly as in the table (\(10^{-2} \to 10^{-3} \to 10^{-5} \to 10^{-10}\)).

Example 3 · Square roots the Babylonian way For \( f(x) = x^2 - 2 \), Newton's step is \[ x_{n+1} = x_n - \frac{x_n^2 - 2}{2x_n} = \frac12\Big(x_n + \frac{2}{x_n}\Big): \] average the guess and \(2\) divided by the guess. From \(x_0 = 1.5\): \(1.4166667\), \(1.4142157\), \(1.4142135624\). Three steps give \(\sqrt2\) to ten digits. This algorithm was known in ancient Mesopotamia, some 3700 years before Newton.
When Newton fails
  • A bad starting point can send the iterates far away. For \( f(x) = \operatorname{arctg}x \) (root \(0\)), starting at \(x_0 = 2\) gives \( x_1 \approx -3.54 \), \( x_2 \approx 13.95 \), ...: the iterates jump back and forth and run off to infinity. The conditions of the theorem (\(f''\) of constant sign, start where \(f f'' > 0\)) prevent this.
  • A horizontal tangent (\(f'(\beta_n) = 0\)) makes the step undefined; a nearly horizontal one throws the next guess very far.

5. The method of iteration

Besides these two procedures, the method of iteration is often used, after bringing equation (1) to the form

\[ x = \varphi(x). \]

Pick a starting value \(x_0\) and compute

\[ x_1 = \varphi(x_0), \quad x_2 = \varphi(x_1), \quad \dots, \quad x_{n+1} = \varphi(x_n). \]

If the sequence converges to some \(\xi\) (and \(\varphi\) is continuous), then \( \xi = \varphi(\xi) \): the limit is a root. Such a \(\xi\) is called a fixed point of \(\varphi\).

Convergence condition If \( |\varphi'(x)| \le q < 1 \) on an interval containing the root and all the iterates, the iteration converges, and \[ |x_n - \xi| \le q^n\,|x_0 - \xi|. \]

Why: by Lagrange's theorem, \( x_{n+1} - \xi = \varphi(x_n) - \varphi(\xi) = \varphi'(c)(x_n - \xi) \), so each step multiplies the error by at most \(q\). If \( |\varphi'| > 1 \) near the root, the error grows instead, and the iteration runs away.

Example 4 · The form matters The equation \( x^3 + x - 1 = 0 \) can be rewritten in many ways:
  • \( x = \frac{1}{1 + x^2} \): here \( |\varphi'(\xi)| = \frac{2\xi}{(1 + \xi^2)^2} \approx 0.64 < 1 \). From \(x_0 = 0.5\): \(0.8,\ 0.6098,\ 0.7290,\ 0.6530,\ 0.7011,\ 0.6705,\ 0.6899,\ 0.6775,\ 0.6854,\ 0.6804,\ \dots\) It converges, oscillating around the root, slowly (the error shrinks by about \(0.64\) per step).
  • \( x = 1 - x^3 \): here \( |\varphi'(\xi)| = 3\xi^2 \approx 1.40 > 1 \). From \(x_0 = 0.5\): \(0.875,\ 0.330,\ 0.964,\ 0.104,\ 0.999,\ 0.003,\ \dots\) It diverges, jumping between \(0\) and \(1\).
Same equation, same root; only the choice of \(\varphi\) decides success. Newton's method is in fact iteration with the clever choice \( \varphi(x) = x - \frac{f(x)}{f'(x)} \), for which \( \varphi'(\xi) = 0 \).

6. The graphical method

For orientation, a graphical procedure is often used first: it shows how many roots there are and roughly where. The trick is to rewrite \(f(x) = 0\) as \( g(x) = h(x) \), with two functions whose graphs are easy to draw, and look for the intersections.

Example 5 · \( x = \cos x \) Draw \(y = x\) and \(y = \cos x\). They cross exactly once, somewhere between \(0.7\) and \(0.8\) (for \(x > 1\) the line is above \(1 \ge \cos x\), and for \(x < 0\) the line is negative while \(\cos x > 0\) on \(\big(-\frac\pi2, 0\big)\)). Then refine:
  • Iteration \( x_{n+1} = \cos x_n \) converges, since \( |\varphi'(x)| = |\sin x| < 1 \) near the root: \(0.540,\ 0.858,\ 0.654,\ 0.793,\ 0.701,\ 0.764,\ 0.722,\ 0.750,\ \dots\) (slowly, oscillating).
  • Newton for \( f(x) = x - \cos x \), \( f'(x) = 1 + \sin x \), from \(x_0 = 1\): \(0.7503639,\ 0.7391129,\ 0.7390851334,\ 0.7390851332\).
The root is \( \xi = 0.7390851332\dots \), sometimes called the Dottie number: press "cos" repeatedly on a calculator (in radians) and you will see it appear.

7. Comparing the methods

MethodNeedsSpeedReliability
Bisectioncontinuity, sign changeslow: error halves each stepalways converges
Chords (regula falsi)sign change, \(f' \ne 0\)linear: error shrinks by a constant factoralways converges (root stays bracketed)
Newton (tangents)\(f'\), good start (\(f f'' > 0\))quadratic: digits double each stepcan diverge from a bad start
Iteration \(x = \varphi(x)\)\( |\varphi'| < 1 \) near the rootlinear, factor \(\approx |\varphi'(\xi)|\)depends on the choice of \(\varphi\)

In practice the methods are combined: a graph or bisection to isolate the root and get a safe starting point, then Newton to polish it to full precision in a few steps. Another classical combination uses chords and tangents together: since they approach the root from opposite sides (Figure 1), the root is always trapped between \(\alpha_n\) and \(\beta_n\), which gives a free error bound.

8. Summary

MethodFormula
Isolation\( f(a)f(b) < 0 \), \( f' \ne 0 \) on \((a, b)\) \(\Rightarrow\) exactly one root
Chords\( \alpha_1 = a - \frac{f(a)}{f(b) - f(a)}(b - a) \), then repeat on the subinterval with a sign change
Newton\( \beta_{n+1} = \beta_n - \frac{f(\beta_n)}{f'(\beta_n)} \), start where \( f f'' > 0 \)
Iteration\( x_{n+1} = \varphi(x_n) \), converges if \( |\varphi'| \le q < 1 \)
Error bound (any method)\( |x_n - \xi| \le \frac{|f(x_n)|}{m} \), \( m = \min|f'| \)
Newton's error\( |\xi - \beta_{n+1}| \le \frac{M}{2m}|\xi - \beta_n|^2 \)

9. Practice problems

Try each one before opening the solution. More solved problems from this topic are in Differential Calculus.

Problem 1: Show that \( x^3 - 2x - 5 = 0 \) has exactly one root in \([2, 3]\).

\( f(2) = -1 < 0 \), \( f(3) = 16 > 0 \), and \( f'(x) = 3x^2 - 2 > 0 \) on \([2, 3]\). (This is the equation Newton himself used to demonstrate his method.)

Problem 2: For the same equation, do one step of the method of chords.

\( \alpha_1 = 2 - \frac{-1}{16 - (-1)}\cdot 1 = 2 + \frac{1}{17} \approx 2.0588 \).

Problem 3: For the same equation, from which endpoint should Newton's method start? Do two steps.

\( f''(x) = 6x > 0 \); \( f(3) > 0 \), so start at \(3\): \( \beta_1 = 3 - \frac{16}{25} = 2.36 \), \( \beta_2 = 2.36 - \frac{f(2.36)}{f'(2.36)} \approx 2.36 - \frac{3.4241}{14.709} \approx 2.1272 \). (The root is \(2.0945515\dots\))

Problem 4: Write Newton's formula for \(\sqrt[3]{a}\) and compute \(\sqrt[3]{10}\) starting from \(2\).

\( f(x) = x^3 - a \): \( x_{n+1} = x_n - \frac{x_n^3 - a}{3x_n^2} = \frac13\Big(2x_n + \frac{a}{x_n^2}\Big) \). From \(2\): \( 2.1667 \), \( 2.15450 \), \( 2.154435 \) (true: \(2.1544347\)).

Problem 5: Will the iteration \( x_{n+1} = e^{-x_n} \) converge to the root of \( x = e^{-x} \)?

The root is near \(0.567\); \( |\varphi'(x)| = e^{-x} \approx 0.567 < 1 \) there. Yes, it converges (oscillating). The limit \(0.5671432\dots\) is called the omega constant.

Problem 6: Find graphically how many roots \( e^x = x + 2 \) has.

The convex curve \(y = e^x\) and the line \(y = x + 2\) intersect twice: once for \(x < 0\) (near \(-1.84\)) and once for \(x > 0\) (near \(1.15\)).

Problem 7: After how many bisection steps is the root of \(x^3 + x - 1 = 0\) on \([0, 1]\) known to within \(10^{-6}\)?

We need \( \frac{1}{2^n} < 10^{-6} \), i.e. \( 2^n > 10^6 \): \( n = 20 \). Newton needs only four steps for a much better result.

Final thoughts

All the methods in this post replace a hard question ("where is the root?") by a sequence of easy ones. The chord pretends the function is a straight line between two points; the tangent pretends it is its own tangent line near one point; iteration turns the equation into a rule for improving a guess. The derivative is what makes them fast: it measures how far to move (Newton), how reliable the result is (\( |f(x_n)|/m \)), and whether an iteration will converge at all (\( |\varphi'| < 1 \)). That is how every calculator and computer actually solves equations.

Related posts: the mean value theorems (error estimates), tangents and normals (the geometry of Newton's step), and Taylor's formula (why Newton converges quadratically).