Search

Search papers and lessons

Newton-Raphson Method

Level 2 · 9 min read

Newton-Raphson finds a root of a function by repeatedly following its tangent line to where it crosses zero, so each guess is usually much closer to the answer than the one before.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Sign in to see your progress

TL;DR

Many problems ask for a number xx where a function ff equals zero. Newton-Raphson solves them (finding such an xx is called finding a root of ff) by starting from a rough guess, drawing the tangent line to the curve at that guess, and moving to the point where the tangent crosses zero. Repeating this step usually closes in on the root very quickly, often doubling the number of correct digits each time.

The method needs only the function and its derivative, so it works on equations that have no neat formula. It sits behind many routines that compute square roots, reciprocals and the solutions of nonlinear equations in engineering and finance.

Where you'll see it: in the solvers inside scientific calculators and numerical libraries, in the inner loop of finding an interest rate that matches a bond price, and in the training of some models that need a second-order step.

Intuition

Follow the slope down to zero

Suppose you want the point where a curve crosses the horizontal axis, and you can see only where you are. Stand at a guess x0x_0 on the curve. The slope there tells you which way the curve is heading. If you assume the curve keeps that slope, you can draw a straight line, the tangent, and ask where that line hits zero. That crossing is usually closer to the true crossing than your guess was.

Move to that new point, draw the tangent again, and repeat. Each line is a better local picture of the curve, so the guesses home in on the root. The method is just this picture written as a rule.

Why the tangent and not something else

A straight line is the simplest curve to solve. The tangent line is the straight line that matches the function's value and slope at one point. Near that point, the tangent is a very good stand-in for the curve, and the error it introduces shrinks as you get closer. That is why the method is accurate once the guesses are already near the root.

−0.500.511.522.5−3−2−10123xy
  • f(x) = x² − 2
  • tangent at x = 1
Starting at x = 1, the tangent to f crosses zero at x = 1.5. That is closer to the true root √2 ≈ 1.41421, marked at the right.

The math

The update rule

Definition: Newton-Raphson iteration

To solve f(x)=0f(x) = 0 with ff differentiable, start from a guess x0x_0 and compute

xn+1=xn−f(xn)f′(xn),n=0,1,2,…x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}, \qquad n = 0, 1, 2, \dots

Here xnx_n is the guess at step nn, f(xn)f(x_n) is the function's value there, and f′(xn)f'(x_n) is its derivative, the slope of the tangent line.

Derive it directly from the tangent. The tangent to ff at xnx_n is the line

y=f(xn)+f′(xn) (x−xn).y = f(x_n) + f'(x_n)\,(x - x_n).

Set y=0y = 0 and solve for xx. Subtracting f(xn)f(x_n) from both sides and dividing by f′(xn)f'(x_n) gives x=xn−f(xn)/f′(xn)x = x_n - f(x_n)/f'(x_n). That xx is the next guess, xn+1x_{n+1}. The formula fails only when f′(xn)=0f'(x_n) = 0, because then the tangent is flat and never crosses zero (unless it lies on the axis).

Why it converges fast

Near a simple root rr, where f(r)=0f(r) = 0 and f′(r)≠0f'(r) \ne 0, the error en=xn−re_n = x_n - r obeys, roughly,

en+1≈C en2,C=f′′(r)2f′(r).e_{n+1} \approx C\, e_n^2, \qquad C = \frac{f''(r)}{2f'(r)}.

This is called quadratic convergence. If the error is 10−310^{-3}, the next error is around C×10−6C \times 10^{-6}. The number of correct digits roughly doubles each step. This is far faster than methods that shrink the error by a fixed fraction each step, such as bisection, which gains about one binary digit per step.

The catch is the word "near". Far from the root, the tangent can point the wrong way, and the iteration may wander off or cycle. Good starting guesses matter.

flowchart LR
  A[Start with guess x0] --> B[Compute f of x and f prime of x]
  B --> C[Update x to x minus f over f prime]
  C --> D{Close enough to zero?}
  D -- no --> B
  D -- yes --> E[Stop: x is the root]

Worked examples

Example
Example 1: the square root of 2 (tiny)

Find 2\sqrt{2} by solving f(x)=x2−2=0f(x) = x^2 - 2 = 0. Here f′(x)=2xf'(x) = 2x, so the update is xn+1=xn−(xn2−2)/(2xn)x_{n+1} = x_n - (x_n^2 - 2)/(2x_n). Start at x0=1x_0 = 1.

  1. f(1)=−1f(1) = -1 and f′(1)=2f'(1) = 2, so x1=1−(−1)/2=1.5x_1 = 1 - (-1)/2 = 1.5.
  2. f(1.5)=0.25f(1.5) = 0.25 and f′(1.5)=3f'(1.5) = 3, so x2=1.5−0.25/3=1.41667x_2 = 1.5 - 0.25/3 = 1.41667.
  3. f(1.41667)≈0.00694f(1.41667) \approx 0.00694 and f′(1.41667)≈2.83333f'(1.41667) \approx 2.83333, so x3=1.41667−0.00245=1.41422x_3 = 1.41667 - 0.00245 = 1.41422.
  4. The true value is 2=1.414214\sqrt{2} = 1.414214. After three steps the error is about 0.0000020.000002.

Interpretation: starting with one correct digit (1.0 vs 1.41), three steps gave about six correct digits. The number of correct digits roughly doubled at each step.

Example
Example 2: a cubic with a real root (standard case)

Solve f(x)=x3−2x−5=0f(x) = x^3 - 2x - 5 = 0. Here f′(x)=3x2−2f'(x) = 3x^2 - 2. Start at x0=2x_0 = 2.

  1. f(2)=8−4−5=−1f(2) = 8 - 4 - 5 = -1 and f′(2)=12−2=10f'(2) = 12 - 2 = 10, so x1=2+1/10=2.1x_1 = 2 + 1/10 = 2.1.
  2. f(2.1)=9.261−4.2−5=0.061f(2.1) = 9.261 - 4.2 - 5 = 0.061 and f′(2.1)=3(4.41)−2=11.23f'(2.1) = 3(4.41) - 2 = 11.23, so x2=2.1−0.061/11.23=2.09457x_2 = 2.1 - 0.061/11.23 = 2.09457.
  3. f(2.09457)≈0.0002f(2.09457) \approx 0.0002 and f′(2.09457)≈11.16f'(2.09457) \approx 11.16, so x3≈2.09457−0.000018=2.094551x_3 \approx 2.09457 - 0.000018 = 2.094551.
  4. The root is x≈2.094551x \approx 2.094551, so x3x_3 is already correct to six decimals.

Interpretation: three steps were enough to reach six decimal places. A bisection search on the same interval would need about 20 steps for the same accuracy.

Example
Example 3: a reciprocal without division (realistic)

Chip designers often compute 1/a1/a with only multiplication and subtraction. Apply Newton-Raphson to f(x)=1/x−af(x) = 1/x - a, which has its root at x=1/ax = 1/a. Since f′(x)=−1/x2f'(x) = -1/x^2, the update simplifies to

xn+1=xn (2−a xn).x_{n+1} = x_n\,(2 - a\,x_n).

Take a=7a = 7, so the target is 1/7=0.1428571/7 = 0.142857, and start at x0=0.1x_0 = 0.1.

  1. x1=0.1 (2−0.7)=0.13x_1 = 0.1\,(2 - 0.7) = 0.13.
  2. x2=0.13 (2−0.91)=0.1417x_2 = 0.13\,(2 - 0.91) = 0.1417.
  3. x3=0.1417 (2−0.9919)=0.14285x_3 = 0.1417\,(2 - 0.9919) = 0.14285.

Interpretation: the update uses only multiplication and subtraction, which is why hardware and software use this form for division. Notice how the correct digits roughly double: after two steps the guess (0.1417) matched the true value 0.142857 to about two digits, and after three steps (0.14285) to about five.

Tradeoffs and failure modes

Newton-Raphson is fast when it works, and it can fail in predictable ways.

SituationWhat goes wrongBetter choice
The starting guess is far from the rootThe tangent may point away, and the iterates can divergeStart with a few bisection steps (halving an interval that contains the root) to bracket the root, then switch
The derivative is zero or nearly zero at an iterateThe update divides by a tiny number and jumps far awayUse a damped step, or a method that does not need the derivative, such as the secant method (which replaces the tangent by a line through the last two guesses)
The root is repeated (the function touches zero without crossing)Convergence drops from quadratic to linearSolve for a modified function such as f/f′f/f', or accept slower steps
The derivative is hard to computeThe method needs more work per step than it savesUse a numerical derivative or the secant method
The function is not smoothThe tangent does not describe the curveUse a bracketing method such as bisection

Even well-behaved functions can cycle. Take f(x)=x3−2x+2f(x) = x^3 - 2x + 2 with x0=0x_0 = 0. Here f(0)=2f(0) = 2 and f′(0)=−2f'(0) = -2, so x1=1x_1 = 1. Then f(1)=1f(1) = 1 and f′(1)=1f'(1) = 1, so x2=0x_2 = 0 again. The iteration bounces between 0 and 1 forever. The fix is a different starting point, not more steps.

The method also says nothing by itself about whether a root exists. Always check the residual ∣f(xn)∣|f(x_n)| and stop when it is small enough for your purpose.

History

The idea of improving a guess with a linear correction is very old. Babylonian and Greek methods for square roots used the same principle, and Heron of Alexandria described one in the first century. Isaac Newton developed a general version in the late 1660s and 1670s, using it to solve polynomial equations, and his method was published in the early 1700s. Joseph Raphson gave a simpler, more algorithmic presentation in 1690, which is why the method carries both names. Thomas Simpson later extended it to systems of equations in 1740. The method caught on because it is fast, general and simple to program, and because the tangent-line picture makes it easy to understand.

Recap

Newton-Raphson solves f(x)=0f(x) = 0 by repeatedly moving to where the tangent line at the current guess crosses zero. Its update xn+1=xn−f(xn)/f′(xn)x_{n+1} = x_n - f(x_n)/f'(x_n) comes from that single line, and near a simple root the error roughly squares at each step. Its weaknesses are bad starting points, flat slopes and cycles. The same idea, applied to a function's slope instead of its zero, is the basis of gradient-based optimisation, and the tangent is the first term of a Taylor series.

Check yourself

QuestionApply one Newton-Raphson step to f(x)=x2−5f(x) = x^2 - 5 starting at x0=2x_0 = 2. What is x1x_1?Show answer

f(2)=4−5=−1f(2) = 4 - 5 = -1 and f′(2)=4f'(2) = 4. So x1=2−(−1)/4=2.25x_1 = 2 - (-1)/4 = 2.25. The true root is 5≈2.236\sqrt{5} \approx 2.236, so one step has already brought the guess within about 0.014.

QuestionWhy does the update fail when f′(xn)=0f'(x_n) = 0?Show answer

The update divides by f′(xn)f'(x_n), which is then undefined. Geometrically, the tangent is horizontal, so it never crosses zero unless it lies on the axis, and there is no unique next guess.

QuestionIn Example 2, why would a bisection method need many more steps than Newton-Raphson to match the accuracy of the final guess?Show answer

Bisection (repeatedly halving an interval known to contain the root) halves the interval each step, gaining roughly one binary digit per step. Newton-Raphson roughly doubles the number of correct digits per step once it is near the root. So for the same number of digits, bisection needs many more steps.

QuestionWhy is the starting point x0=0x_0 = 0 a poor choice for f(x)=x3−2x+2f(x) = x^3 - 2x + 2?Show answer

At x0=0x_0 = 0 the derivative is −2-2 and the tangent is steep and sends the next guess to x1=1x_1 = 1, which in turn sends the iteration back to x2=0x_2 = 0. The iteration cycles and never converges. A starting point nearer the real root, where the tangent is a better picture of the curve, avoids this.

Sources