Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 39 Ā· Applications of Derivatives

Newton's Method

Learn Newton's method for approximating roots of equations using tangent lines, with a step-by-step derivation, code and a look at when it fails.

Some equations cannot be solved with algebra. There is no neat formula for the solution of cos(x) = x, or of x⁵ + x = 7. But we can often find a very accurate approximate answer, and calculus provides one of the fastest ways: Newton's method. It uses tangent lines to home in on a root.

The idea

A root of f is a number x with f(x) = 0. Suppose you have a guess xā‚€ that is close to a root. The curve near xā‚€ looks almost like its tangent line there. The tangent line crosses the x-axis at a point that is usually much closer to the root than xā‚€ was. Take that crossing point as the new guess, and repeat.

The tangent line at xā‚€ is y = f(xā‚€) + f'(xā‚€)(x - xā‚€). Setting y = 0 and solving for x gives the next guess:

Text
x₁ = xā‚€ - f(xā‚€) / f'(xā‚€)

In general, the rule is:

Text
x_{n+1} = x_n - f(x_n) / f'(x_n)
flowchart LR
    A["Guess x_n"] --> B["Draw tangent at x_n"]
    B --> C["Find where it meets the x-axis"]
    C --> D["That is x_n+1"]
    D --> A

Each pass replaces the curve with a straight line and solves the easy problem.

Example: the square root of 2

The number √2 is the positive root of f(x) = x² - 2. Here f'(x) = 2x, so the update is:

Text
x_{n+1} = x_n - (x_n² - 2) / (2 x_n) = (x_n + 2/x_n) / 2

Start with xā‚€ = 1. Then x₁ = (1 + 2)/2 = 1.5, and xā‚‚ = (1.5 + 2/1.5)/2 = 1.41666..., which is already correct to two decimals. This is the same recipe that ancient mathematicians used for square roots, now with a calculus explanation.

Python Newton's method from scratch

Press Run (or Ctrl + Enter) to see the result here.

Program input Ā· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You should see the number of correct digits roughly double with each step. This is called quadratic convergence, and it is why Newton's method is so popular. Near a simple root, the error after one step is roughly proportional to the square of the error before it.

A harder equation: cos x = x

Rewrite as f(x) = cos(x) - x = 0. Here f'(x) = -sin(x) - 1. A rough sketch shows the curves y = cos x and y = x cross once near x = 0.7, so start there. The following code stops automatically when two guesses agree to a tiny tolerance, and compares the result with scipy's built-in root finder.

Python Solve cos(x) = x

Press Run (or Ctrl + Enter) to see the result here.

Program input Ā· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When Newton's method fails

Newton's method is powerful, but it is not magic. Watch out for these problems:

  • f'(x_n) = 0. The tangent line is horizontal and never meets the x-axis, so you cannot divide.
  • A bad starting guess. The first tangent may throw you far from the root you want, or toward a different root.
  • Cycling. For some functions and guesses the iterates bounce back and forth between two values forever. For f(x) = x³ - 2x + 2, starting at xā‚€ = 0 gives x₁ = 1, then xā‚‚ = 0 again.
  • Slow convergence at repeated roots. Where f touches the axis without crossing (like x² at 0), the method still converges but only about half a digit per step.

The next TryIt demonstrates the cycle.

Python A cycle: Newton's method going nowhere

Press Run (or Ctrl + Enter) to see the result here.

Program input Ā· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In practice, mix methods: a safe method such as bisection finds a rough interval, and Newton's method polishes the answer. Plot the function first so your starting guess is sensible.

Check your understanding

Quick check Ā· 4 questions

of 4 answered You scored / 4 Ā· perfect!

  1. 1. Newton's method uses which formula to get the next guess?

    The tangent line at x_n crosses the axis at x_n - f(x_n)/f'(x_n).
  2. 2. For f(x) = x² - 2 starting at xā‚€ = 1, what is x₁?

    x₁ = 1 - (1 - 2)/(2Ā·1) = 1 + 0.5 = 1.5.
  3. 3. Which situation makes a Newton step impossible?

    A zero derivative means a horizontal tangent line, and the formula would divide by zero.
  4. 4. What does quadratic convergence mean in practice?

    Near a simple root, the number of correct digits roughly doubles at each iteration.

Summary

  • Newton's method replaces a curve by its tangent line and solves for where that line meets the axis.
  • The update rule is x_{n+1} = x_n - f(x_n)/f'(x_n).
  • It converges very fast near a simple root but can fail with flat tangents, poor starting guesses or cycles.
  • Pair it with a plot or a safe bracketing method for reliability.

Next: Antiderivatives and Indefinite Integrals