Follow the tangent line
Bisection uses only the signs of . Newton's method also uses how steep the graph is, and when it works it is far faster.
Close up, a smooth curve looks almost straight. The straight line that touches the curve at a point, running in the same direction there, is its tangent line. A line is easy to solve, so Newton's method solves the tangent instead of the curve.
Guess a root, . Follow the tangent at down to where it crosses the axis, and call that point . Repeat from to get , and so on: is the guess after steps.
The slope of a curve, borrowed for now
A line has the same slope everywhere. A curve is steeper in some places than in others, so its slope depends on the point. Write , read "f prime of x", for the slope of the tangent at .
Lesson 2.2.1 shows where the slope of a curve comes from. For now, borrow three facts. The slope of at is , and the slope of is .
Adding a term adds to the slope. Adding a constant changes nothing: it only shifts the graph up or down (lesson 1.1.2).
| slope |
Try it
You can check a borrowed slope with rise over run (lesson 1.2.1) across a tiny step. The cell takes the chord from to .
For at 1.5 the chord slope is 3.0, and gives 3.0. For at 1.5 both give 5.75. round(…, 4) hides the last digits, which differ because the step is not zero.
The Newton step
The tangent at passes through the point with slope . By the point-slope form of lesson 1.2.1, it is the line
The next guess is where this line crosses the axis. Set and solve for , as in lesson 0.3.2: .
Rule: Newton's method
Step sideways by the height divided by the slope . The slope must not be 0. If is already a root, then and the guess stays where it is.
A first example:
Take , with slope , and start at . There and the slope is 4, so . As a line, the tangent is , which crosses the axis at .
Two Newton steps for from . The tangent at 2 lands on 1.5; the tangent at 1.5, enlarged, lands on 1.41667, almost on .
Here are the guesses, with each one's error, its distance from .
| step | guess | error |
|---|---|---|
| 0 | 2 | 0.586 |
| 1 | 1.5 | 0.0858 |
| 2 | 1.4166666666666667 | 0.00245 |
| 3 | 1.4142156862745099 | 0.0000021 |
| 4 | 1.4142135623746899 | 0.0000000000016 |
| 5 | 1.4142135623730951 | 0 |
Five steps give to every digit a computer stores. Bisection needed 20 steps for six digits.
Algebra gives the step a neat form. For it simplifies to an average:
Each new guess is the average of and . If is too big then is too small, so their average lands in between. This rule for square roots is often called the Babylonian method.
Press Next step to follow the tangents yourself. Then pick , the cubic from lesson 1.3.2, and count the steps: bisection needed 27.
Explore
Press Next step. Each step follows the tangent line at the current guess down to where it crosses zero, which is the next guess.
- Steps
- 0
- Current guess
- 2
- f there
- 2
- Distance from the root 1.414214
- 0.585786437627
A second example: the cubic
Take , with slope , from . The first step is , to four places.
| step | guess | error |
|---|---|---|
| 1 | 1.3478260869565217 | 0.0231 |
| 2 | 1.325200398950907 | 0.000482 |
| 3 | 1.3247181739990537 | 0.00000022 |
| 4 | 1.3247179572447898 | 0.000000000000044 |
| 5 | 1.324717957244746 | 0 |
Four steps reach an error below . Bisection took 27 steps to reach .
Why it is so fast
Look at the errors for : 0.0858, 0.00245, 0.0000021, 0.0000000000016. Each is about a third of the square of the one before. Squaring a small number doubles its zeros after the point, as shows.
So near a root, the number of correct digits roughly doubles each step. Bisection gains the same small amount every step, about three decimal places per 10 steps. Newton's method gains more and more, but only once it is close: far from the root its first steps can go anywhere.
A program needs a rule for when to stop. Stop when a step moves the guess by less than a tolerance. Also give up after a fixed number of steps, so a failure cannot run for ever.
Try it
newton follows that rule. It returns the root and the number of steps, counting the last tiny step that shows the guess has stopped moving.
It finds in 6 steps, the cubic's root in 5, and the cube root of 10, 2.15443469, in 5 from .
When Newton's method fails
Newton's speed comes with no guarantee. Each failure below is one you will meet in practice.
- A flat tangent. If , the tangent never meets the axis and the step divides by zero: from fails at once. A nearly flat tangent is almost as bad. From 0.1 the first step lands at 10.05, and it takes eight steps to get back to .
- A cycle. Take , with slope , from . and give ; then and give , the start again. The guesses bounce between 0 and 1 for ever, while the only root is near .
- A double root. For , with slope , the step simplifies to . From 3 the guesses are 2, 1.5, 1.25, 1.125: the error only halves each step, no faster than bisection.
- No root. has no real root, so the guesses can never settle. From 0.5 they go , 0.29, , , 0.84, jumping about for ever.
- The wrong root. has slope . From 1.5, halfway between the roots 1 and 2, one step lands on 3. The start decides which root you get, and it need not be the nearest.
To watch the cycle, pick in the explorer above and press Next step a few times.
Using it safely
Careful code guards Newton's method. It caps the number of steps and checks at the answer. It can also keep a bracket from lesson 1.3.2, taking a bisection step whenever a Newton step would leave it.
SciPy's brentq (lesson 1.3.2) mixes safe and fast steps in a similar way. SciPy's newton(f, x0, fprime=slope) runs plain Newton's method, and raises RuntimeError when it has not converged after 50 steps. Without fprime, it estimates each slope from a chord through its last two guesses, so it needs no slope at all.
Try it
The first two lines find , with the slope and without it. The last digit differs by rounding.
The third call is the cycle. After 50 steps newton is still at 0, and it raises RuntimeError.
Case study 1.3.5 uses newton without a slope to find interest rates. Lesson 2.4.3 works out the slope of any function with calculus and runs Newton's method again. Case study 2.4.6 uses it for an option's implied volatility.
Common mistakes
- Subtract the step: . Adding it sends the guess the wrong way.
- Divide the height by the slope, , not the slope by the height.
- Use the slope at the current guess, , not the slope at the start.
- A zero slope divides by zero. Start somewhere else.
- It is fast only near the root. Far away the guesses can jump, cycle or wander, so cap the steps and check at the answer.
- A double root slows it down to one halving of the error per step.
- The start picks the root, and not always the nearest one. Nothing keeps the guesses inside a bracket unless you add it.
Newton's method
0 of 11 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- Newton's method follows the tangent line at the current guess down to the axis: , where is the slope at .
- The step comes from the point-slope form , set to 0.
- Near a root the correct digits roughly double each step, far faster than bisection.
- It can fail: a flat tangent, a cycle, a double root (slow), no root, or a jump to an unexpected root. Cap the steps, check at the answer, and fall back on a bracket.
- In SciPy:
newton(f, x0, fprime=...)for Newton's method (withoutfprimeit uses chord slopes), andbrentq(f, a, b)for a safe bracketed search.