Newton's Method
Newton's method solves by repeatedly replacing with its tangent line. It is the workhorse inside numerical solvers, from square-root instructions to implicit physics integrators and option-pricing code. This lesson derives it, proves why it converges quadratically, analyses how it fails, and shows it running inside a real solver. The survey lesson Newton's Method covers the basic iteration and the square-root story.
The iteration
The tangent at is . Setting :
It is the root of the linear approximation of at .
Why it converges quadratically
Let be a root with , continuous, and write . Taylor's theorem with remainder (expand around , evaluate at ):
If and near , then . Once the errors shrink, and each step roughly doubles the number of correct digits. The ratio tends to , which we can watch:
from decimal import Decimal as D, getcontext
getcontext().prec = 80
f = lambda x: x.exp() - 3 * x
df = lambda x: x.exp() - 3
r = D("1.5121345516578424738967396780720387046036") # root, to 40 digits
x = D(2)
for n in range(6):
x_new = x - f(x) / df(x)
e, e_new = x - r, x_new - r
print(f"n={n} error {float(abs(e_new)):.3e} e_(n+1)/e_n^2 = {float(e_new / e**2):.6f}")
x = x_new
print("predicted limit f''(r)/(2f'(r)) =", round(float(r.exp() / (2 * (r.exp() - 3))), 6))n=0 error 1.714e-01 e_(n+1)/e_n^2 = 0.720061
n=1 error 3.135e-02 e_(n+1)/e_n^2 = 1.067242
n=2 error 1.354e-03 e_(n+1)/e_n^2 = 1.377964
n=3 error 2.698e-06 e_(n+1)/e_n^2 = 1.471751
n=4 error 1.075e-11 e_(n+1)/e_n^2 = 1.476297
n=5 error 1.706e-22 e_(n+1)/e_n^2 = 1.476306
predicted limit f''(r)/(2f'(r)) = 1.476306
How it fails
| Failure | Cause | Remedy |
|---|---|---|
| division by zero / huge jump | (flat tangent) | damp the step, or switch method |
| cycling | e.g. from | better start, line search |
| divergence | : each step doubles the distance from 0 | bracketing (bisection, Brent) |
| jumping to another root | start in another root's basin | bracket the wanted root first |
| only linear convergence | multiple root, | use for a root of multiplicity |
At a double root , the error ratio tends to instead of 0: one more correct bit per step instead of doubling digits. Multiplying the step by the multiplicity restores quadratic speed:
f = lambda x: (x - 1)**2 * (x + 2)
df = lambda x: 2 * (x - 1) * (x + 2) + (x - 1)**2
for m, name in [(1, "plain Newton "), (2, "modified, m = 2")]:
x, errs = 2.0, []
for _ in range(6):
if f(x) == 0:
break
x -= m * f(x) / df(x)
errs.append(abs(x - 1))
print(name, " ".join(f"{e:.1e}" for e in errs))plain Newton 5.6e-01 3.0e-01 1.6e-01 8.0e-02 4.0e-02 2.0e-02
modified, m = 2 1.1e-01 1.9e-03 6.3e-07 6.7e-14 0.0e+00
Newton inside a solver: an implicit physics step
Stiff equations (fast springs, chemical kinetics, circuit simulation) blow up with the explicit Euler step. The implicit (backward) Euler step instead defines the new state by an equation, , solved with Newton at every time step. For :
def implicit_step(y, h):
z = y # previous state is a good first guess
for it in range(1, 20):
dz = (z - y + h * z**3) / (1 + 3 * h * z**2)
z -= dz
if abs(dz) < 1e-14:
return z, it
raise RuntimeError("Newton did not converge")
y, h = 2.0, 0.5 # a large step: explicit Euler would go to y = -2
for step in range(1, 5):
y, its = implicit_step(y, h)
print(f"t = {step * h:.1f} y = {y:.10f} ({its} Newton iterations)")
exact = lambda t: 2 / (1 + 8 * t) ** 0.5 # solution of y' = -y^3, y(0) = 2
print("exact y(2) =", round(exact(2.0), 10))t = 0.5 y = 1.1795090246 (7 Newton iterations)
t = 1.0 y = 0.8607018058 (6 Newton iterations)
t = 1.5 y = 0.6937527075 (5 Newton iterations)
t = 2.0 y = 0.5906982071 (5 Newton iterations)
exact y(2) = 0.4850712501
Explicit Euler from with gives , already the wrong sign. The implicit step stays stable at any step size, at the price of a few Newton iterations, and the remaining gap to the exact value is the first-order accuracy of backward Euler, not a solver problem. Physics engines (cloth, soft bodies) and circuit simulators (SPICE) run this loop millions of times.
In software
- Solvers: SciPy's
newton, the Newton–Raphson loop in SPICE, implicit integrators in physics engines, and the "Newton–Krylov" methods for huge systems all solve this way, usually with a damped step and a fallback. - Finance: implied volatility and internal rate of return (IRR) have no closed form; spreadsheets'
IRR()and options libraries use Newton (or a safeguarded variant). - Hardware arithmetic: and start from a small table estimate and use one or two Newton steps to reach full precision.
- Optimisation: Newton applied to gives , the second-order optimisation step; quasi-Newton methods (BFGS, L-BFGS) approximate .
Exercises
Exercise 1: Two steps by hand
Do two Newton steps for from .
Answer
, (true ).
Solution
x = 2.0
for _ in range(2):
x -= (x**3 - 5) / (3 * x**2)
print(round(x, 7))1.75
1.7108844
Exercise 2: A cycle
Show that Newton on from cycles.
Answer
Solution
Exercise 3: Internal rate of return
An investment of 1000 pays 300, 400 and 500 at the ends of years 1, 2, 3. Find the rate with by Newton in the variable .
Answer
(8.90% per year).
Solution
In , the equation is the polynomial , , which is positive for , so there is one positive root.
p = lambda v: 500 * v**3 + 400 * v**2 + 300 * v - 1000
dp = lambda v: 1500 * v**2 + 800 * v + 300
v = 1.0
for _ in range(8):
v -= p(v) / dp(v)
print("v =", round(v, 8), " r =", round(1 / v - 1, 6))v = 0.91830451 r = 0.088963
Exercise 4: Predict the error ratio
For near , what does tend to?
Answer
.
Solution
.
Test yourself
Near a simple root, Newton's errors satisfy roughly…
What happens to plain Newton at a double root?
- It diverges
- It converges cubically
- It stops at the first step
- It converges, but only linearly (error ratio )
Why does an implicit Euler step need Newton's method?
- To compute the derivative of the solution
- The new state is defined by an equation that must be solved
- To choose the step size
- It does not; implicit Euler is explicit