TExcelTAD
Home › Calculus in Depth › Newton's Method

Newton's Method

Newton's method solves f(x)=0f(x) = 0 by repeatedly replacing ff 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 xnx_n is y=f(xn)+f′(xn)(x−xn)y = f(x_n) + f'(x_n)(x - x_n). Setting y=0y = 0:

xn+1=xn−f(xn)f′(xn)(requires f′(xn)≠0)x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} \qquad \text{(requires } f'(x_n) \ne 0\text{)}

It is the root of the linear approximation of ff at xnx_n.

Why it converges quadratically

Let rr be a root with f′(r)≠0f'(r) \ne 0, f′′f'' continuous, and write en=xn−re_n = x_n - r. Taylor's theorem with remainder (expand around xnx_n, evaluate at rr):

0=f(r)=f(xn)+f′(xn)(r−xn)+12f′′(ξn)(r−xn)2,ξn between xn and rDivide by f′(xn) and rearrange:xn−f(xn)f′(xn)−r⏟en+1=12⋅f′′(ξn)f′(xn)⋅(xn−r)2=[f′′(ξn)2f′(xn)]⋅en2\begin{aligned} &0 = f(r) = f(x_n) + f'(x_n)(r - x_n) + \tfrac{1}{2} f''(\xi_n)(r - x_n)^2, \quad \xi_n \text{ between } x_n \text{ and } r \\ &\text{Divide by } f'(x_n) \text{ and rearrange:} \\ &\underbrace{x_n - \frac{f(x_n)}{f'(x_n)} - r}_{e_{n+1}} = \frac{1}{2} \cdot \frac{f''(\xi_n)}{f'(x_n)} \cdot (x_n - r)^2 = \left[\frac{f''(\xi_n)}{2f'(x_n)}\right] \cdot e_n^2 \end{aligned}

If ∣f′′∣≤M\lvert f'' \rvert \le M and ∣f′∣≥m>0\lvert f' \rvert \ge m > 0 near rr, then ∣en+1∣≤M2men2\lvert e_{n+1} \rvert \le \frac{M}{2m} e_n^2. Once M2m∣en∣<1\frac{M}{2m}\lvert e_n \rvert < 1 the errors shrink, and each step roughly doubles the number of correct digits. The ratio en+1/en2e_{n+1}/e_n^2 tends to f′′(r)2f′(r)\frac{f''(r)}{2f'(r)}, which we can watch:

python · try it yourself
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 f′(xn)≈0f'(x_n) \approx 0 (flat tangent) damp the step, or switch method
cycling e.g. f(x)=x3−2x+2f(x) = x^3 - 2x + 2 from x0=0x_0 = 0 better start, line search
divergence x3\sqrt[3]{x}: 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, f′(r)=0f'(r) = 0 use xn−m⋅f/f′x_n - m \cdot f/f' for a root of multiplicity mm

At a double root f(x)=(x−r)2g(x)f(x) = (x - r)^2 g(x), the error ratio en+1/ene_{n+1}/e_n tends to 12\frac{1}{2} instead of 0: one more correct bit per step instead of doubling digits. Multiplying the step by the multiplicity restores quadratic speed:

python · try it yourself
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 zz by an equation, z=y+hg(z)z = y + h g(z), solved with Newton at every time step. For y′=−y3y' = -y^3:

F(z)=z−y+hz3=0,F′(z)=1+3hz2(never 0, good for Newton)F(z) = z - y + h z^3 = 0, \qquad F'(z) = 1 + 3h z^2 \quad \text{(never 0, good for Newton)}
python · try it yourself
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 y=2y = 2 with h=0.5h = 0.5 gives 2−0.5⋅8=−22 - 0.5 \cdot 8 = -2, 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 F(z)=0F(z) = 0 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: 1/x1/x and 1/x1/\sqrt{x} start from a small table estimate and use one or two Newton steps to reach full precision.
  • Optimisation: Newton applied to f′(x)=0f'(x) = 0 gives x←x−f′(x)/f′′(x)x \leftarrow x - f'(x)/f''(x), the second-order optimisation step; quasi-Newton methods (BFGS, L-BFGS) approximate f′′f''.

Exercises

Exercise 1: Two steps by hand

Do two Newton steps for f(x)=x3−5f(x) = x^3 - 5 from x0=2x_0 = 2.

Answer

x1=7/4=1.75x_1 = 7/4 = 1.75, x2≈1.7108844x_2 \approx 1.7108844 (true 53≈1.7099759\sqrt[3]{5} \approx 1.7099759).

Solution
xn+1=xn−xn3−53xn2x1=2−312=1.75x2=1.75−5.359375−53⋅3.0625=1.75−0.3593759.1875≈1.7108844\begin{aligned} x_{n+1} &= x_n - \frac{x_n^3 - 5}{3x_n^2} \\ x_1 &= 2 - \frac{3}{12} = 1.75 \\ x_2 &= 1.75 - \frac{5.359375 - 5}{3 \cdot 3.0625} = 1.75 - \frac{0.359375}{9.1875} \approx 1.7108844 \end{aligned}
python · try it yourself
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 f(x)=x3−2x+2f(x) = x^3 - 2x + 2 from x0=0x_0 = 0 cycles.

Answer

0→1→0→1…0 \to 1 \to 0 \to 1 \ldots

Solution
f′(x)=3x2−2x1=0−2−2=1x2=1−11=0\begin{aligned} f'(x) &= 3x^2 - 2 \\ x_1 &= 0 - \frac{2}{-2} = 1 \\ x_2 &= 1 - \frac{1}{1} = 0 \end{aligned}

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 rr with −1000+3001+r+400(1+r)2+500(1+r)3=0-1000 + \frac{300}{1+r} + \frac{400}{(1+r)^2} + \frac{500}{(1+r)^3} = 0 by Newton in the variable v=11+rv = \frac{1}{1 + r}.

Answer

r≈0.0890r \approx 0.0890 (8.90% per year).

Solution

In vv, the equation is the polynomial p(v)=500v3+400v2+300v−1000p(v) = 500v^3 + 400v^2 + 300v - 1000, p′(v)=1500v2+800v+300p'(v) = 1500v^2 + 800v + 300, which is positive for v>0v > 0, so there is one positive root.

python · try it yourself
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 f(x)=x2−3f(x) = x^2 - 3 near r=3r = \sqrt{3}, what does en+1/en2e_{n+1}/e_n^2 tend to?

Answer

123≈0.2887\frac{1}{2\sqrt{3}} \approx 0.2887.

Solution

f′′(r)2f′(r)=22⋅23=123\frac{f''(r)}{2f'(r)} = \frac{2}{2 \cdot 2\sqrt{3}} = \frac{1}{2\sqrt{3}}.

Test yourself

Near a simple root, Newton's errors satisfy roughly…

  1. en+1≈Cen2e_{n+1} \approx C e_n^2
  2. en+1≈en/2e_{n+1} \approx e_n / 2
  3. en+1≈en−Ce_{n+1} \approx e_n - C
  4. en+1≈ene_{n+1} \approx \sqrt{e_n}

What happens to plain Newton at a double root?

  1. It diverges
  2. It converges cubically
  3. It stops at the first step
  4. It converges, but only linearly (error ratio →1/2\to 1/2)

Why does an implicit Euler step need Newton's method?

  1. To compute the derivative of the solution
  2. The new state is defined by an equation z=y+hg(z)z = y + h g(z) that must be solved
  3. To choose the step size
  4. It does not; implicit Euler is explicit