Using the Slope: the Secant Method and Newton–Raphson
Finding a root faster than bisection: the secant method as regula falsi without a bracket, Newton–Raphson when the slope is known, convergence faster than linear, and when the slope misleads.
Last updated:
Warm-up: what do you already know?
Two points of the graph are given, and . Where does the line through them cross the -axis?
Solution
The line is . Setting gives . This is the point of regula falsi.
The secant method: regula falsi without a bracket
A shop offers a laptop for 1200 in cash, or in six monthly instalments of 220, the first one in a month.
The monthly interest rate hidden in the offer solves .
We solved this equation on the bisection page and the regula falsi page:
for a tolerance of bisection needs 40 steps and regula falsi 11, and both need a bracket.
In regula falsi one end of the interval may also stay in place forever.
We now meet methods that are even faster.
In regula falsi, at each step we computed the zero of the line joining the two bracketing ends, and the new point came closer and closer to the true root.
To decide which end to replace by the new point, we checked the sign of the function.
Work it out: what happens if we drop the sign check, and instead of replacing an end according to the sign we always replace the older approximation by the new one, that is, we join the two latest points we computed by a line?
What is the next point ?
Solution
The line through and crosses the axis at the point from the warm-up, with and :
.
The point you found is the formula for in regula falsi, with the two latest points in place of the two ends.
This is the secant method.
What it adds to regula falsi: no sign check and no bracket, and it always keeps the two most recent points, so no endpoint stays fixed.
It needs only values of . Its cost: it loses the guarantee of the bracket.
The starting points need not enclose the root, nothing forces the root to stay between them, so the method can diverge.
If the denominator is zero: the line is horizontal and never crosses the axis.
Its order of convergence is (the golden ratio), not linear like regula falsi.
We do the proof in the practice session.
Why ? The diagonal of a square with side 1 has length , an irrational number:
it has no representation as a fraction or as a finite decimal, so we cannot write it in full, only approach it.
The equation defines it, and a numerical method gives at each step a better approximation, to as many digits as we want.
Try it: with the secant method on from and , what is ?
Solution
and , so , where the root is (an error of about ).
Newton–Raphson: follow the tangent
The of the instalments has a derivative: a sum of six terms we can write down.
When there is a formula for , we can stop approximating the slope from two points and use the slope itself:
instead of two points at every step we use one, which continues the idea of the secant method.
Instead of a secant line we get a tangent, the secant line when the two points merge.
The tangent to at is .
Work it out: where does the tangent cross the -axis?
Solution
Set : , so , provided . For a nearly straight curve this point is very close to the true root, and it is cheap:
one value and one slope.
Replace the curve by its tangent at the current point and jump to where the tangent crosses zero.
This is the Newton–Raphson method:
Where the formula comes from, step by step, in a short video of mine (in Hebrew):
What Newton adds to the secant method: the exact slope instead of an approximation of it, so there is no need for two starting points, and the method is faster.
Its cost: the derivative , and a start near the root.
A simple example: with , and the root is .
A Newton step is . From :
| Step | Estimate | at the estimate | Error |
|---|---|---|---|
| 0 | 1.5 | 0.25 | |
| 1 | 1.416666666667 | 0.006944 | |
| 2 | 1.414215686275 | ||
| 3 | 1.414213562375 |
Three Newton steps give an error of . By the explorer’s rule (threshold ) bisection on needs 36 steps, the secant method 8 and Newton 4.
Work it out: Bisection cuts the error by a factor of 2 at each step.
How many steps does it take to gain one decimal digit, that is, to cut the error by a factor of 10?
Solution
After steps the error is smaller by a factor of , and when .
Four steps cut the error by 16 and three only by 8, so bisection gains one decimal digit every 3.3 steps on average.
We measure how accurate an estimate is by its number of correct digits:
for an absolute error it is , so an error of has 4 correct digits after the decimal point.
Write for the error at step , the difference between the estimate and the root .
In the table, the error at step 0 has 1.1 correct digits and the error at step 1 has 2.6.
Work it out: (1) Write a formula that expresses in terms of and explains the correct digits in the table.
(2) Write such a formula for bisection too, which cuts the error by a factor of 2 at each step.
Candidate formulations
Check each formulation against the rows of the table.
- “The new error is exactly the square of the previous one”, .
- “The new error is half the previous one”, .
- “The new error is roughly the square of the previous one, times a constant”, .
Solution
- The first formulation is wrong already at the first step: , while the error in the table is . The second is bisection, and it does not fit the table: the error drops by far more than half. The third fits: with a constant . In the table the ratio is about , and at the three steps. The square alone, , gives 5.2 digits, and the actual error gives 5.7: about more digits thanks to , since .
- : the same form, with power 1 instead of 2.
The formal definition
A method has order of convergence when its errors satisfy
that is, near the root. is linear convergence and is quadratic.
- Bisection: the error bound is halved at each step, so and for the bound, not for the error itself. The error itself need not shrink at every step: for on the errors at the first midpoints are , and , and the ratios of the errors are and then .
- Secant: (at a root where ).
- Newton–Raphson: the convergence is at least quadratic; of order exactly 2 when (at a root where ).
In the definition is finite; for linear convergence () also .
Continuing with the table: the correct digits are 1.1, 2.6, 5.7 and 11.8, and the ratios between consecutive steps are 2.4, 2.2 and 2.1, approaching 2 as the iterates approach the root.
This is quadratic convergence, against the steady gain of a fixed number of digits per step of linear methods.
The errors in the table are computed in high-precision arithmetic.
A computer working in double precision keeps about 16 digits, and the evaluation of is itself rounded, so one more step would stop at an absolute error of the order of .
Below that level the limit is the arithmetic, not the method.
Steps to reach on the two problems of the page, by the explorer’s rule:
| Method | Monthly instalments | |
|---|---|---|
| Bisection | 40 | 36 |
| Regula falsi | 11 | 15 |
| Secant | 5 | 8 |
| Newton–Raphson | 4 | 4 |
(Brackets and ; the secant method starts from the two ends of the bracket, and Newton from and .) In the explorer further down press Compare all methods to see the four error curves together.
Steps are not the whole cost. Newton evaluates and at every step, the secant method only , so a secant step can be cheaper.
By how much depends on the problem: if costs as much as the saving is about half, but when reuses work already done for it costs little extra and the saving is small.
To compare methods fairly, we count evaluations of and of and measure the running time on our own function.
A method of order multiplies the number of correct digits by in each step; if a step needs evaluations, the factor per evaluation is .
Calculate: when costs as much as , how many evaluations does a step of Newton need, and how many a step of the secant method?
What is the factor per evaluation of each, and which method gains digits faster per evaluation of ?
Solution
Newton has and , so its factor is . The secant method has and , so its factor is , larger:
per evaluation of , the secant method gains digits faster.
The explorer below holds all the examples of the page as tabs, and in each one you can choose any of the four methods.
The monthly instalments and compare the methods. The other three tabs show that Newton’s cost is the conditions it needs:
the derivative , and a start near the root. The explanation of each example appears under the row of examples.
The explorer needs JavaScript. The table above shows the number of steps of the four methods, and the three ways Newton fails are: an almost zero slope (the tangent is nearly horizontal and the next point is flung far away), a cycle between two points, and divergence.
A full tutorial on the Newton–Raphson method, and a short video on running the iteration with the ANS and CALC keys of a scientific calculator:
Run Newton’s iteration yourself on the emulator, with the Ans key (the last answer), for :
A scientific calculator also has a built-in equation solver, the SOLVE function.
According to the manufacturer’s documentation it solves with Newton’s method, from the starting value you give it, so a good start matters here too:
Where does Newton land? The conditions Newton needs are about the start.
Try it: choose a function, drag the start along the axis, predict where the tangents lead (to which root, to a cycle, or away to infinity), and watch.
After a few predictions open the map of all starts: the boundaries between its bands are where a tiny change of start changes the outcome.
The lab needs JavaScript. The explorer above shows Newton’s method from a start of your choice.
The ladder so far
| Method | Uses | Convergence | Needs | Main risk |
|---|---|---|---|---|
| Bisection | signs | linear, halves the error | a bracket | slow |
| Regula falsi | values, a chord | usually faster | a bracket | an end gets stuck |
| Secant | values, two latest points | order 1.62 | two starts | may diverge |
| Newton–Raphson | values and slope | order 2, digits double | and a good start | flat slope, cycles, divergence |
In practice, scientific libraries combine them: a safe bracket for the guarantee and a fast method for the speed, as in Brent’s method (SciPy’s brentq).
Continue learning
The next step is the practice session for this lecture: a table by hand, an implied volatility of a real option as a real problem, the usual mistakes, transfer questions and a Python implementation.
Repeating a Rule looks at fixed-point iteration, the idea behind many iterative methods, and at inverse quadratic interpolation, which together with bisection forms the Brent method used in practice.
My tutorial on fixed-point iteration, and on the multidimensional Newton–Raphson method: