Lesson

Repeating a Rule: Fixed-Point Iteration and Inverse Quadratic Interpolation

Fixed-point iteration and why its error shrinks by the factor |g′|, Newton as a special case, inverse quadratic interpolation without a derivative, and how Brent’s method combines the fast steps with bisection.

Last updated:


Warm-up: what do you already know?

1. On a scientific calculator set to radians, type any number and press = so that it is stored in Ans.
Then type cos(Ans) and press = again and again. What happens to the displayed number?

A: It grows without bound

The cosine always lies between −1-1 and 11⁠, so the displayed number stays in that range.

B: It settles on one number, 0.7390851…

Each press replaces xx by cos⁡x\cos x⁠. The number settles where pressing the key changes nothing:
a number that equals its own cosine. This lesson explains why it settles, and how fast.

C: It jumps among the same few numbers forever

That can happen to other rules, but not to the cosine key.

Check it on the calculator. The emulator below does exactly this, key by key.
The guide shows the keys; press them yourself.

An iteration that repeats one rule

In bisection, regula falsi and Newton–Raphson and the secant method we looked for a root:
a number with f(x)=0f(x)=0⁠. Here is another way to pose a question.
Take a function gg and look for a number that gg leaves unchanged:

g(x∗)=x∗g(x^*)=x^*

Such a number is a fixed point of gg⁠. To find it, start anywhere and apply the rule again and again:

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

This is fixed-point iteration. The calculator experiment is exactly this with g(x)=cos⁡xg(x)=\cos x⁠.
The fixed point is x∗=0.7390851332…x^*=0.7390851332\ldots⁠, the root of f(x)=cos⁡x−xf(x)=\cos x-x⁠. Starting from x0=1x_0=1⁠, with the error en=∣xn−x∗∣e_n=|x_n-x^*|⁠:

nnxnx_nError ene_nen/en−1e_n/e_{n-1}
01.000000.261
10.540300.1990.76
20.857550.1180.60
30.654290.08480.72
40.793480.05440.64
50.701370.03770.69
60.763960.02490.66
70.722100.01700.68
80.750420.01130.67

The iterates jump to both sides of x∗x^*⁠, and the error shrinks by a factor that seems to settle near 0.67.
That is linear convergence, like bisection but with a different factor.
Where does the number come from?

Work it out: the error after one step is xn+1−x∗=g(xn)−g(x∗)x_{n+1}-x^*=g(x_n)-g(x^*)⁠. Replace gg near x∗x^* by its tangent line there.
What does the error become?

Solution

Near x∗x^* the tangent gives g(xn)≈g(x∗)+g′(x∗)(xn−x∗)g(x_n)\approx g(x^*)+g'(x^*)(x_n-x^*)⁠. Subtracting g(x∗)g(x^*) leaves xn+1−x∗≈g′(x∗) (xn−x∗)x_{n+1}-x^*\approx g'(x^*)\,(x_n-x^*)⁠.
Each step multiplies the error by g′(x∗)g'(x^*)⁠.

So the ratio tends to ∣g′(x∗)∣|g'(x^*)|⁠. For the cosine, g′(x)=−sin⁡xg'(x)=-\sin x and ∣g′(x∗)∣=sin⁡0.7390851…=0.6736|g'(x^*)|=\sin 0.7390851\ldots=0.6736⁠, which matches the last rows of the table.
This gives the rule:

  • if ∣g′(x∗)∣<1|g'(x^*)|<1 and the start is close enough, the iteration converges, linearly, with factor ∣g′(x∗)∣|g'(x^*)|⁠;
  • if ∣g′(x∗)∣>1|g'(x^*)|>1⁠, the iterates move away from x∗x^*⁠;
  • if ∣g′(x∗)∣=1|g'(x^*)|=1⁠, this test does not decide the outcome: the iteration neither converges nor runs away because of the derivative alone, and it can cycle. For g(x)=2xg(x)=\dfrac2x we have g′(2)=−1g'(\sqrt2)=-1⁠, and from the start 1 the iterates are 1,2,1,2,…1,2,1,2,\ldots forever;
  • if g′(x∗)=0g'(x^*)=0⁠, the error shrinks faster than linearly.

With the factor 0.6736 each step gains −log⁡100.6736=0.172-\log_{10}0.6736=0.172 correct digits, so one more digit costs about 5.8 steps.
A signed factor explains the zigzag: g′(x∗)g'(x^*) is negative here, so the error changes sides at every step.

The same equation, different rules

One equation can be rewritten as x=g(x)x=g(x) in many ways, and the choice of gg decides everything.
For x2−2=0x^2-2=0 (the root is 2\sqrt2⁠) here are three rules, with g′g' evaluated at the root:

Rule g(x)g(x)g′(2)g'(\sqrt2)What happens
2x\dfrac{2}{x}−1-1from 1 it gives 1, 2, 1, 2, … forever
x2+x−2x^2+x-21+22≈3.831+2\sqrt2\approx3.83from 1.5 it gives 1.5, 1.75, 2.8125, 8.72, … and runs away
12(x+2x)\dfrac{1}{2}\left(x+\dfrac{2}{x}\right)00from 1.5 it gives 1.5, 1.41667, 1.414216, … and the digits double

The third rule is Newton’s method. In general, Newton’s method for f(x)=0f(x)=0 is the fixed-point iteration with g(x)=x−f(x)f′(x)g(x)=x-\dfrac{f(x)}{f'(x)}⁠.
Differentiate gg⁠, using the quotient rule for the fraction:

g′(x)=1−f′(x) f′(x)−f(x) f′′(x)f′(x)2=1−1+f(x) f′′(x)f′(x)2=f(x) f′′(x)f′(x)2\begin{aligned} g'(x)&=1-\frac{f'(x)\,f'(x)-f(x)\,f''(x)}{f'(x)^2}\\ &=1-1+\frac{f(x)\,f''(x)}{f'(x)^2}\\ &=\frac{f(x)\,f''(x)}{f'(x)^2} \end{aligned}

At the root f(x∗)=0f(x^*)=0⁠, so g′(x∗)=0g'(x^*)=0 as long as f′(x∗)≠0f'(x^*)\neq0⁠. The error factor is zero, and that is why Newton’s method is faster than linear:
the quadratic convergence of Newton–Raphson is the case g′(x∗)=0g'(x^*)=0⁠.

Why quadratic? When g′(x∗)=0g'(x^*)=0 the tangent to gg at the fixed point is horizontal, so the tangent approximation gives 0 and does not tell us how large the error is.
The next term in the approximation of gg near x∗x^* (the second-order Taylor expansion, with the second derivative) gives its size:

xn+1−x∗≈12 g′′(x∗) (xn−x∗)2x_{n+1}-x^*\approx\frac12\,g''(x^*)\,(x_n-x^*)^2

The new error is about a constant times the square of the previous error, and that is quadratic convergence.
For Newton’s method, differentiating g′g' once more and substituting f(x∗)=0f(x^*)=0 gives

g′′(x∗)=f′′(x∗)f′(x∗)g''(x^*)=\frac{f''(x^*)}{f'(x^*)}

So the convergence is quadratic exactly when f′′(x∗)≠0f''(x^*)\neq0⁠. When f′′(x∗)=0f''(x^*)=0 the quadratic term vanishes as well, and the convergence is faster still.
A check on the third rule of the table: for f(x)=x2−2f(x)=x^2-2 we get g′′(2)=222≈0.707g''(\sqrt2)=\dfrac{2}{2\sqrt2}\approx0.707⁠, and the errors of the three values in the table, computed without rounding, are 0.08580.0858⁠, 0.002450.00245 and 0.00000210.0000021⁠.
From the first error the formula predicts 12⋅0.707⋅0.08582≈0.0026\tfrac12\cdot0.707\cdot0.0858^2\approx0.0026⁠, close to 0.002450.00245⁠, and from the second 12⋅0.707⋅0.002452≈0.0000021\tfrac12\cdot0.707\cdot0.00245^2\approx0.0000021⁠.

Try it. The lab draws each rule as a staircase: from xnx_n go up to the curve y=g(x)y=g(x)⁠, then across to the line y=xy=x⁠, which gives xn+1x_{n+1}⁠.
A fixed point is where the curve crosses the line. Pick a rule, decide how the iteration will end, and watch.

The lab needs JavaScript. The table above shows the same rules from the starts given there.

A real example: a slope that is computed once

Return to the implied volatility of the SPX option from Newton–Raphson and the secant method, f(σ)=C(σ)−425.6f(\sigma)=C(\sigma)-425.6 with the root σ∗=0.16295375229691\sigma^*=0.16295375229691⁠.
Newton recomputes the slope (vega) at every step. What if we compute it once, at the start σ0=0.3\sigma_0=0.3⁠, where vega is m=2095.44m=2095.44⁠, and keep it fixed?

σn+1=σn−f(σn)m\sigma_{n+1}=\sigma_n-\frac{f(\sigma_n)}{m}

This is a fixed-point iteration with g(σ)=σ−f(σ)/mg(\sigma)=\sigma-f(\sigma)/m⁠, and its factor is:

g′(σ∗)=1−vega(σ∗)m=1−2081.152095.44=0.0068g'(\sigma^*)=1-\dfrac{\text{vega}(\sigma^*)}{m}=1-\dfrac{2081.15}{2095.44}=0.0068

The factor is tiny because vega hardly changes between 0.3 and the root.
The computed errors:

Stepff at the estimateErrorError ratio
0286.71.4×10−11.4\times10^{-1}
10.4652.2×10−42.2\times10^{-4}0.0016
23.2×10−33.2\times10^{-3}1.5×10−61.5\times10^{-6}0.0068
32.2×10−52.2\times10^{-5}1.0×10−81.0\times10^{-8}0.0068
41.5×10−71.5\times10^{-7}7.1×10−117.1\times10^{-11}0.0068
51.0×10−91.0\times10^{-9}4.8×10−134.8\times10^{-13}0.0068

The first step is identical to Newton’s, since the slope is the same.
After that the ratio is the predicted 0.0068: linear, but with two correct digits gained per step.
Four steps bring the error below 10−1010^{-10}⁠, one more than Newton, and the slope was computed once.
The method is cheap per step and needs no new derivative, but it is only as good as the slope you froze:
from a start far away, where vega is very different, the factor is no longer small.

Try it. The lab freezes the slope of Newton’s method for x2−2=0x^2-2=0 at a number mm you choose, g(x)=x−x2−2mg(x)=x-\dfrac{x^2-2}{m}⁠, and asks you to bring the error down in as few steps as you can.

The lab needs JavaScript. The table above shows the frozen slope on the option problem.

Inverse quadratic interpolation: more points, no derivative

The secant method draws a line through two points. With three points we can fit a parabola, which follows the curve more closely.
The difficulty is that a parabola y=p(x)y=p(x) may miss the xx-axis, and when it crosses it we must choose between two crossings.

The trick of inverse quadratic interpolation is to swap the roles:
fit xx as a quadratic function of yy⁠. The point we want is the one where y=0y=0⁠, so we evaluate the parabola at y=0y=0⁠.
There is no equation to solve and exactly one answer. For three points (a,fa)(a,f_a)⁠, (b,fb)(b,f_b)⁠, (c,fc)(c,f_c) with distinct values fa,fb,fcf_a,f_b,f_c⁠, build the quadratic function as a sum of three terms, one for each point.
The term of the point (a,fa)(a,f_a) is

a⋅(y−fb)(y−fc)(fa−fb)(fa−fc)a\cdot\frac{(y-f_b)(y-f_c)}{(f_a-f_b)(f_a-f_c)}

When y=fay=f_a the numerator equals the denominator, and the term equals aa⁠.
When y=fby=f_b or y=fcy=f_c the numerator is zero, and the term equals 0.
The other two terms are built in the same way around bb and cc⁠, so the sum of the three is a quadratic function of yy that equals aa at y=fay=f_a⁠, bb at y=fby=f_b and cc at y=fcy=f_c⁠:
it passes through the three points. Substituting y=0y=0⁠, the numerator of the first term is (−fb)(−fc)=fbfc(-f_b)(-f_c)=f_b f_c⁠, and likewise in the other two.
The result is the formula

xn+1=a fbfc(fa−fb)(fa−fc)+b fafc(fb−fa)(fb−fc)+c fafb(fc−fa)(fc−fb).\begin{aligned} x_{n+1}&=\frac{a\,f_b f_c}{(f_a-f_b)(f_a-f_c)}\\ &\quad+\frac{b\,f_a f_c}{(f_b-f_a)(f_b-f_c)}\\ &\quad+\frac{c\,f_a f_b}{(f_c-f_a)(f_c-f_b)}. \end{aligned}

In the next step the oldest point is dropped and the new one is added.
The method uses only values of ff⁠, like the secant method.
Its convergence order is about 1.841.84 (the real root of t3=t2+t+1t^3=t^2+t+1⁠), between the secant method’s 1.62 and Newton’s 2.
Take the same option problem, with the three starting points 0.050.05⁠, 0.30.3 and 11⁠, where ff equals −227.4-227.4⁠, 286.7286.7 and 1724.71724.7⁠:

StepEstimateff at the estimateError
10.16057147540169−4.96-4.962.4×10−32.4\times10^{-3}
20.16293391142215−4.1×10−2-4.1\times10^{-2}2.0×10−52.0\times10^{-5}
30.162953756883729.5×10−69.5\times10^{-6}4.6×10−94.6\times10^{-9}
40.162953752296912.8×10−132.8\times10^{-13}1.3×10−161.3\times10^{-16}

Four steps, as many as the secant method needs (five each by the explorer’s rule, see the extended ladder below), without a derivative (the errors are computed in high-precision arithmetic; in double precision the last one is limited by rounding, at the order of 10−1610^{-16}⁠).
The cost: the formula divides by differences of the values ff⁠, so it fails if two of them are equal, and if the three points are badly spread the parabola can send the next point far away.
There is also no bracket.

Try it. The lab draws the inverse parabola sideways through three points of the curve and marks where it crosses the axis.
Drag the points, estimate the crossing, then check; step to the next round and watch the points change.
Compare with the secant line through the last two points.

The lab needs JavaScript. The table above shows the same rounds for the option problem.

Brent’s method: speed with a guarantee

The fast methods so far buy speed with certainty: Newton, the secant method and fixed-point iteration keep no bracket, and regula falsi keeps one but an end can stay fixed, so the bracket width need not shrink to 0.
Bisection halves the bracket at every step, but it is slow. Brent’s method keeps both.
It keeps a bracket around the root, as bisection does. At each step it tries a fast candidate, inverse quadratic interpolation or the secant step.
If the candidate falls inside the bracket and the bracket shrinks enough, it is accepted; otherwise the method falls back on a bisection step.
The bracket therefore always shrinks, so the root is never lost, and when the function is well behaved the fast steps do most of the work.
This is the method behind SciPy’s brentq, the usual library choice for one equation in one unknown on an interval where the sign changes.

The test for a good short step has two parts. The candidate must lie well inside the bracket:
less than three quarters of the bracket’s width from the best point.
And it must be shorter than half the step before last, so that the method really is faster than halving.
A candidate that fails either part is dropped, and the method bisects.
Open the lab, predict each decision, and see which functions make Brent fall back on bisection and which let the fast steps run.

The lab needs JavaScript. Brent’s method is the one behind SciPy’s brentq.

The ladder, extended

Steps to reach 10−1010^{-10} on the implied-volatility problem, counted by two stopping rules:

MethodSteps, true error below 10−1010^{-10}Steps, the explorer’s ruleNeedsMain risk
Bisection3243a bracketslow
Regula falsi45a bracketan end can stay fixed
Secant45two startsmay diverge
Slope fixed once46one slopeslow if it changes
Inverse quadratic45three startsequal values, a wild parabola
Newton–Raphson33f′f' and a good startflat slope, cycles, divergence

The count depends on the stopping rule. In the first column we stop when the true error, the distance from the root, is below 10−1010^{-10} (the root is known here from high-precision arithmetic).
A program does not know the root, so the explorer’s rule, also used in the table of steps in Newton–Raphson and the secant method, stops when both the step and ∣f∣|f| are at most 10−1010^{-10}⁠; this costs one or two more steps, and 11 more for bisection.
In exact arithmetic Newton needs 4 steps by the explorer’s rule; in double precision ff is exactly 0 at the third step, so the explorer stops there.
By either rule the inverse quadratic method and the secant method need the same number of steps here.
| Brent | safe by design | a bracket | a more complex program |

(The starting points are those of the examples above. Brent’s method has no entry in the steps column because its count depends on how many of its steps are fast ones.)

Continue learning

The next step is the practice session for this lecture: predicting the factor by hand, the usual mistakes and a Python implementation.
You can also revisit the explorer of Newton–Raphson and the secant method and see which of its examples would behave like the three rules of the table above.

My tutorial on fixed-point iteration is at the end of the Newton–Raphson and the secant method.