Any slope, from the rules
Lesson 1.3.3 ran Newton's method on a few borrowed slopes: those of and , and the fact that adding adds . Module 2.3 now gives the slope of any function built from powers, products, quotients, exponentials and logs. So Newton's method works for all of them.
The step is the same. The tangent at the guess is the line of lesson 2.2.1, and the next guess is where it crosses zero.
Rule: Newton's method
is a height and a slope, so their ratio is in input units: the distance to step sideways. The slope must not be 0.
Solving
No formula gives . So take and look for its root. The product rule (lesson 2.3.2), with as its own slope (lesson 2.3.4), gives
Start at . There and , so .
| step | guess | |
|---|---|---|
| 1 | 0.6839397205857212 | 0.355 |
| 2 | 0.5774544771544498 | 0.0287 |
| 3 | 0.5672297377301171 | 0.000239 |
| 4 | 0.5671432965302959 | 0.0000000169 |
| 5 | 0.567143290409784 |
The root is . The last value of is zero up to rounding: the computer keeps about 16 digits (lesson 2.1.1).
Try it
The cell runs five steps with the slope from the product rule. Each line prints the step, the guess and there.
2.220446049250313e-16 is Python's way of writing .
How fast: the error squares
Write for the root and for the error of guess . Here are the errors for from , with the number of correct digits, (lesson 1.4.3).
| step | error | correct digits | |
|---|---|---|---|
| 0 | 0.433 | 0.4 | |
| 1 | 0.117 | 0.9 | 0.62 |
| 2 | 0.0103 | 2.0 | 0.76 |
| 3 | 0.0000864 | 4.1 | 0.81 |
| 4 | 0.00000000612 | 8.2 | 0.82 |
The correct digits go 1, 2, 4, 8: they double. The last column settles near 0.82, so each error is about 0.82 times the square of the one before. An error that squares each step is called quadratic convergence.
Rule: Quadratic convergence
This holds near a root where . The constant uses the second derivative of lesson 2.4.2; module 2.7 shows where it comes from.
For , , and the constant at is 0.819, the number the table settles on. For of lesson 1.3.3, and , so the constant is . That is the "about a third" lesson 1.3.3 saw.
At a double root , so the rule fails. That is why lesson 1.3.3 saw the error of only halve each step.
Try it
The cell takes eight steps and uses the last guess as the root. Each line is an error, its digits, and its ratio to the previous error squared.
The last line works out with .
The explorer below starts on from 1.5, the cubic of lesson 1.3.3, whose slope is by the power rule (lesson 2.3.1). Press Next step and watch the distance from the root in the readout: about 0.023, then 0.00048, then 0.00000022. Each error is roughly the square of the last, scaled by a constant.
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
- 1.5
- f there
- 0.875
- Distance from the root 1.324718
- 0.175282042755
Good starts and bad starts
From , every guess for landed right of the root: 0.684, then 0.577, then 0.5672. Concavity explains it. is positive for , so the curve is concave up there and lies above each tangent (lesson 2.4.2).
Follow such a tangent down from to zero. There the curve, which lies above the tangent, is still above zero, so the root is further left. Each guess therefore lands between the root and the previous guess: it never overshoots.
From a start left of the root it overshoots once: gives , and the guesses then march back from the right.
A start that runs away
has its root at 0. The product rule (lesson 2.3.2), with as the slope of (lesson 2.3.4), gives , as in lesson 2.4.1. From :
| step | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| guess | 4 | 5.3333 | 6.5641 | 7.7438 |
| 0.0733 | 0.0257 | 0.0093 | 0.0034 |
The values of shrink towards 0, yet the guesses move away from the root. Past its peak at 1, the curve sinks towards the axis without reaching it, and the tangents get flatter.
Algebra shows it never stops. The step simplifies to , which is more than whenever .
At the tangent is flat and the step divides by 0. From the guesses go , , , : straight to the root.
Two starts. For the curve bends up, so each tangent lies below it and every guess lands between the root and the last guess. For from 2, each tangent is flatter than the last and the guesses run away from the root at 0.
Lesson 1.3.3 met the other failures: a flat tangent, a cycle, a double root, no root, and an unexpected root.
Try it
Four steps of Newton's method on , from 2 and from 0.5. Each pair is a guess and the value of there.
From 2 the values look as if they are reaching 0, but the guesses are not.
Newton or bisection?
Bisection (lesson 1.3.2) and Newton's method make opposite trades. Here both solve to :
| bisection on | Newton from 1 | |
|---|---|---|
| needs | a sign change | a slope and a start |
| each step | halves the bracket | about doubles the digits |
| steps to | 40 | 6 |
| can fail? | no, once bracketed | yes |
Newton's count includes a last tiny step that shows the guess has stopped moving, as in lesson 1.3.3. Bisection needs 40 steps because is the first power of 2 above .
Newton with a bracket
Careful code gets both: Newton's speed and bisection's guarantee. Keep a bracket with a sign change. After each guess, shrink the bracket to the half that still changes sign, as bisection does.
Rule: Newton with a bracket
A Newton step that would leave the bracket, or a flat tangent, is replaced by a bisection step. The root never escapes, and near it the Newton steps take over.
Try it
safe_newton starts at the midpoint and follows the rule above. It returns the root and the number of steps.
The cycle function of lesson 1.3.3, on , takes 7 steps. Plain Newton from the midpoint would jump to first. on takes 7 steps; plain Newton from its midpoint 1.5 runs away to 4.5, then 5.79.
SciPy's brentq (lesson 1.3.2) mixes safe and fast steps in a similar way, with chords instead of tangents. Practice set 2.4.4 asks you to write this solver, and case study 2.4.6 needs it for options whose price curve is almost flat.
Newton for a minimum
A local minimum is a root of (lesson 2.4.1), and Newton's method finds roots. Its step then divides by the slope of , which is .
Rule: Newton for a critical point
Newton's method applied to instead of . It finds any critical point, so check the answer with (lesson 2.4.2): positive means a minimum, negative a maximum.
Take , with and . From the guesses are 1.166667, 1.132616, 1.130905 and 1.130901. There , so it is a minimum, with value .
The start decides which critical point you get. From 0, Newton lands on 0.169938, where : a maximum. From it lands on , a second minimum with the lower value .
Try it
The loop runs five steps from 1, then prints and at the answer.
SciPy's newton(f, x0, fprime=…) runs the same method. Here it gets and , from 0 and from .
Common mistakes
- Use the slope from the rules at the current guess. A wrong derivative still moves the guess, but convergence slows or fails. A central difference (lesson 2.2.2) is a quick check.
- A small is not a small error. For from 2, falls to 0.0034 while the guess runs off past 7.
- Quadratic convergence needs . At a double root the error only halves.
- The start matters. For , any start above 1 runs away, and a start at 1 has a flat tangent.
- Fast is not safe. When you cannot pick a good start, keep a bracket and bisect whenever a step leaves it.
- For a minimum, give Newton and , not and , and check the sign of at the answer.
Newton's method with derivatives
0 of 12 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
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 works for any you can differentiate with the rules of module 2.3.
- Near a root with , : the correct digits double each step.
- On a concave-up rising curve, a start right of the root never overshoots. A start where the curve flattens towards the axis can run away, while looks small.
- Bisection is slow and certain; Newton is fast and can fail. Newton with a bracket bisects whenever a step would leave the bracket.
- For a critical point, apply Newton to : , then check the sign of .