TactivergeLite

Lite / Intelligent Robotic Systems / Week 7

Newton's method: ride the tangent

Bisection needs about 20 steps for six decimal places. Newton's method often needs four. What's the catch?

About 40 min · 3 goals · Checked by automated tests · Full interactive version

Why should I care?

Newton's method uses the slope of the function to jump straight towards the root. Near a well-behaved root it roughly doubles the number of correct digits every step, which is why calculators and microcontrollers use it for square roots. But it trusts the tangent, and tangents can lie.

Predict

Newton's method on x² − 2 from x₀ = 1 gives x₁ = 1.5, then x₂ ≈ 1.41667. Roughly how many correct decimal places will x₃ have?

  1. About 2
  2. About 5
  3. About 12
Guess first, then reveal

About 5: x₃ = 577/408 ≈ 1.4142157 (error ≈ 2 × 10⁻⁶). x₄ is correct to about 12 places. The number of correct digits roughly doubles each step: quadratic convergence.

Discover

Choose x² − 2 and Newton. Step four times and compare the error column with bisection's. Then choose arctan x (Newton trap): start at 1.0, then at 1.5. What does the tangent do from 1.5?

What the interactive shows (text version)

The stepper shows Newton's method on x² − 2 from 1: the orange tangent at each guess meets the axis at the next guess, 1.5, 1.41667, 1.4142157, with the error column shrinking from 10⁻¹ to 10⁻³ to 10⁻⁶ to 10⁻¹². For arctan x from 1.5, each tangent lands further away and the readout reports divergence.

You can also open the interactive on the full site when you have a faster connection.

Watch (optional)

Watch for: Watch the first part, where Newton's method is introduced as following the tangent line to zero, and notice how the starting guess decides where you end up.

Starts with Newton's method as a practical root finder, then shows beautifully how sensitive it is to the starting guess.

“Newton’s fractal (which Newton knew nothing about)” by 3Blue1Brown (opens YouTube; streaming video uses a lot of data)

The video is optional. Everything you need is in this lesson's text.

Understand

Fast when close

From a good starting guess, Newton's method converges quadratically: the number of correct digits roughly doubles each step. For x² − 2 from 1, four steps give about 12 correct digits, where bisection on [0, 2] would need about 40.

It needs the derivative

You must supply f′(x), worked out by hand or estimated numerically. If f′(x_k) = 0 the tangent is flat and never crosses zero: the method can't continue. Guard against it and cap the number of steps.

It can run away

If the start is far from the root, or the function flattens out, the tangent can throw the next guess further away. arctan x from x₀ = 1.5 diverges. Engineers often bracket first with bisection, then switch to Newton once close, or reject any Newton step that leaves the bracket.

Explain it another way

Intuitive

You're on a hillside in fog and want to reach sea level. Look at the slope under your feet and walk straight downhill as if the slope never changed. Near the coast that works brilliantly; on a long flat plateau it can send you miles the wrong way.

Technical

Stop when |x_{k+1} − x_k| < tol or |f(x)| < tol, and after a maximum number of steps. A secant method replaces f′ with the slope through the last two points: slightly slower but needs no derivative.

Mathematical

For f(x) = arctan x, x_{k+1} = x_k − (1 + x_k²)·arctan x_k. If |x₀| exceeds about 1.39, each step overshoots further, so |x_k| grows without bound.

Applied

The fast inverse square root used in some graphics and embedded code finishes with one Newton step, because a single step from a rough guess already gives close to full accuracy.

Derivation: Where the Newton update comes from
  1. Near a guess x_k, replace the curve by its tangent line: y ≈ f(x_k) + f′(x_k)·(x − x_k).

  2. Find where that line crosses zero: 0 = f(x_k) + f′(x_k)·(x − x_k).

  3. Solve for x: x_{k+1} = x_k − f(x_k)/f′(x_k). This needs f′(x_k) ≠ 0.

  4. For f(x) = x² − c, f′(x) = 2x, so x_{k+1} = x_k − (x_k² − c)/(2x_k) = (x_k + c/x_k)/2: average the guess with c divided by the guess.

  5. Near a simple root the error obeys e_{k+1} ≈ C·e_k², so an error of 10⁻³ becomes about 10⁻⁶, then 10⁻¹². That's quadratic convergence.

Worked example 1

Newton's method with a step limit and a flat-slope guard, compared with the true root.

import math


def newton(f, df, x, tol=1e-12, max_steps=20):
    """Return (estimate, steps). Raises ValueError on a flat tangent or no convergence."""
    for step in range(1, max_steps + 1):
        slope = df(x)
        if slope == 0:
            raise ValueError(f"flat tangent at x = {x}")
        x_new = x - f(x) / slope
        if abs(x_new - x) < tol:
            return x_new, step
        x = x_new
    raise ValueError("did not converge")


root, steps = newton(lambda x: x * x - 2, lambda x: 2 * x, 1.0)
print(root, steps, abs(root - math.sqrt(2)) < 1e-15)   # 1.414213562373095 6 True

try:
    newton(math.atan, lambda x: 1 / (1 + x * x), 1.5)
except (ValueError, OverflowError) as err:
    print("arctan from 1.5:", type(err).__name__)

Common mix-ups

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

Practice 3. Newton's method on f(x) = x² − 4 starts at x₀ = 0. What happens?
Practice 4. Which statement compares bisection and Newton fairly?

Apply it

Write a hybrid solver: keep a bisection bracket, try a Newton step each iteration, and fall back to bisection whenever Newton would leave the bracket. Test it on x³ − 2x − 5 on [2, 3] and on arctan x on [−1, 2], and count steps compared with pure bisection.

Reflect

Why might a safety-critical system prefer a slower method with a guarantee?

Write your answer on paper or in your own notes. Lite never stores what you write.

← Bisection: trap the answer, halve the trapSpeed from position, distance from speed: calculus on samples →