πŸ“ The Newton-Raphson Method

A Level Maths Year 2 Β· Numerical Methods

Level 3 · Ages 17–18

← Back to topic overview
1 Follow the Tangent Down to the Axis

The Newton-Raphson method is the most powerful root-finder in the course. It uses calculus: near a root, a curve looks almost like its tangent, and a tangent is a straight line whose $x$-intercept is easy to find. So we replace the curve by its tangent, see where the tangent crosses the axis, and repeat.

x y 2 2.5 3 5 10 15 xβ‚€ x₁ xβ‚‚ y = xΒ³ βˆ’ 2x βˆ’ 5 tangent at xβ‚€
Start at a first approximation $x_0$. Draw the tangent to $y = \mathrm{f}(x)$ at $\big(x_0, \mathrm{f}(x_0)\big)$. Where it meets the $x$-axis is the next approximation $x_1$ β€” usually much closer to the root. In the diagram, $x_0 = 3$ gives $x_1 = 2.36$ and then $x_2 = 2.127$, closing in fast on the root $2.0946$.
2 Deriving the Formula
Worked Example 1 β€” Derivation from the tangent

Show that the tangent to $y = \mathrm{f}(x)$ at $x = x_n$ meets the $x$-axis at $x_n - \dfrac{\mathrm{f}(x_n)}{\mathrm{f}'(x_n)}$.

β‘ The tangent passes through $\big(x_n, \mathrm{f}(x_n)\big)$ with gradient $\mathrm{f}'(x_n)$.
β‘‘Its equation is $y - \mathrm{f}(x_n) = \mathrm{f}'(x_n)(x - x_n)$.
β‘’On the $x$-axis $y = 0$: $\;-\mathrm{f}(x_n) = \mathrm{f}'(x_n)(x - x_n)$.
β‘£Divide by $\mathrm{f}'(x_n)$ (which must not be zero): $x - x_n = -\dfrac{\mathrm{f}(x_n)}{\mathrm{f}'(x_n)}$, so $x = x_n - \dfrac{\mathrm{f}(x_n)}{\mathrm{f}'(x_n)}$.
The Newton-Raphson formula
$x_{n+1} = x_n - \dfrac{\mathrm{f}(x_n)}{\mathrm{f}'(x_n)}$
Calculator technique. Store $x_0$, then type the whole formula with Ans, e.g. for $\mathrm{f}(x) = x^3 - 2x - 5$:
Ans βˆ’ (AnsΒ³ βˆ’ 2Ans βˆ’ 5) Γ· (3AnsΒ² βˆ’ 2) and press = repeatedly.
3 Using the Method
Worked Example 2 β€” A cubic

$\mathrm{f}(x) = x^3 - 2x - 5$. Taking $x_0 = 2$, use the Newton-Raphson method to find the root to $5$ decimal places.

β‘ $\mathrm{f}'(x) = 3x^2 - 2$, so $x_{n+1} = x_n - \dfrac{x_n^3 - 2x_n - 5}{3x_n^2 - 2}$.
β‘‘$x_1 = 2 - \dfrac{8 - 4 - 5}{12 - 2} = 2 - \dfrac{-1}{10} = 2.1$
β‘’$x_2 = 2.1 - \dfrac{0.061}{11.23} = 2.094568\ldots$
β‘£$x_3 = 2.0945515\ldots$,  $x_4 = 2.0945515\ldots$
β‘€The root is $2.09455$ to $5$ d.p.
Look at the number of correct digits: $x_1$ has $1$, $x_2$ has $4$, $x_3$ has $9$. Close to a root the number of correct decimal places roughly doubles each step β€” far faster than fixed point iteration.
Worked Example 3 β€” Square roots by hand

Use the Newton-Raphson method on $\mathrm{f}(x) = x^2 - 2$ with $x_0 = 1$ to approximate $\sqrt2$.

β‘ $\mathrm{f}'(x) = 2x$, so $x_{n+1} = x_n - \dfrac{x_n^2 - 2}{2x_n} = \dfrac{x_n^2 + 2}{2x_n}$.
β‘‘$x_1 = \dfrac{3}{2} = 1.5$,  $x_2 = \dfrac{17}{12} = 1.41666\ldots$,  $x_3 = \dfrac{577}{408} = 1.4142156\ldots$
β‘’$\sqrt2 = 1.4142135\ldots$, so $x_3$ is already correct to $5$ decimal places.
Worked Example 4 β€” Choosing the starting value

The equation $\mathrm{e}^x = 3x$ has two roots. Use the Newton-Raphson method to find each to $4$ d.p., using $x_0 = 0$ and $x_0 = 1.5$.

β‘ $\mathrm{f}(x) = \mathrm{e}^x - 3x$, $\mathrm{f}'(x) = \mathrm{e}^x - 3$.
β‘‘From $x_0 = 0$: $x_1 = 0 - \dfrac{1}{-2} = 0.5$, $x_2 = 0.61006$, $x_3 = 0.61900$, $x_4 = 0.61906$. Root $\approx 0.6191$.
β‘’From $x_0 = 1.5$: $x_1 = 1.51236$, $x_2 = 1.51213$, $x_3 = 1.51213$. Root $\approx 1.5121$.
The method finds the root nearest the start only if the start is good. Use a sketch or a change of sign to choose $x_0$ sensibly.
Worked Example 5 β€” With logarithms

Use the Newton-Raphson method with $x_0 = 1.5$ to solve $\ln x + x = 2$, giving the root to $4$ d.p., and verify your answer.

β‘ $\mathrm{f}(x) = \ln x + x - 2$, $\mathrm{f}'(x) = \dfrac1x + 1$.
β‘‘$x_1 = 1.5 - \dfrac{\ln 1.5 - 0.5}{1.6667} = 1.55672$,  $x_2 = 1.55715$,  $x_3 = 1.55715$.
β‘’Verify with the bounds for $1.5571$: $\mathrm{f}(1.55705) = -0.000157\ldots < 0$ and $\mathrm{f}(1.55715) = 0.0000072\ldots > 0$. Change of sign, so the root is $1.5571$ to $4$ d.p.
4 When Newton-Raphson Fails

The formula divides by $\mathrm{f}'(x_n)$. Trouble comes whenever that gradient is zero or small β€” that is, when $x_n$ is at or near a stationary point.

ProblemWhat happens
$\mathrm{f}'(x_0) = 0$The tangent is horizontal and never meets the $x$-axis. The formula needs division by zero.
$\mathrm{f}'(x_0)$ close to $0$The tangent is nearly flat, so $x_1$ is thrown a long way off β€” perhaps to a different root, or outside the domain.
Bad starting valueThe iterates can oscillate in a cycle or diverge.
Domain issuesAn iterate may land where $\mathrm{f}$ is undefined, e.g. a negative number in $\ln x$.
x y βˆ’2 βˆ’1 1 2 βˆ’1 1 3 xβ‚€ = 0.95 x₁ β‰ˆ βˆ’2.44 Ξ± y = xΒ³ βˆ’ 3x + 1 stationary point
Worked Example 6 β€” Starting near a stationary point

$\mathrm{f}(x) = x^3 - 3x + 1$ has roots near $-1.88$, $0.35$ and $1.53$. Explain what happens when the Newton-Raphson method is used with (a) $x_0 = 1$  (b) $x_0 = 0.95$.

β‘ $\mathrm{f}'(x) = 3x^2 - 3$, which is zero at $x = \pm1$.
β‘‘(a) $\mathrm{f}'(1) = 0$: the tangent at $x = 1$ is horizontal, so $x_1$ cannot be calculated β€” the method fails immediately.
β‘’(b) $\mathrm{f}(0.95) = -0.9926$, $\mathrm{f}'(0.95) = -0.2925$, so $x_1 = 0.95 - \dfrac{-0.9926}{-0.2925} = -2.4436$.
β‘£From there: $-2.0238,\ -1.8927,\ -1.8795,\ \ldots \to -1.8794$. The method converges β€” but to the root at $-1.88$, not the nearest root $0.35$.
Because $x_0 = 0.95$ is close to the minimum at $x = 1$, the nearly horizontal tangent hurls $x_1$ to the far side of the graph. Always check that $\mathrm{f}'(x_0)$ is not close to zero.
Worked Example 7 β€” A cycle

Apply the Newton-Raphson method to $\mathrm{f}(x) = x^3 - 2x + 2$ with $x_0 = 0$.

β‘ $\mathrm{f}'(x) = 3x^2 - 2$.
β‘‘$x_1 = 0 - \dfrac{2}{-2} = 1$.
β‘’$x_2 = 1 - \dfrac{1 - 2 + 2}{3 - 2} = 1 - 1 = 0$.
β‘£We are back at $x_0$: the sequence goes $0, 1, 0, 1, \ldots$ for ever and never approaches the real root (which is near $-1.77$).
5 Quick Reference

Formula

$x_{n+1} = x_n - \dfrac{\mathrm{f}(x_n)}{\mathrm{f}'(x_n)}$

Geometry

$x_{n+1}$ is where the tangent at $x_n$ meets the $x$-axis.

Set up

Write $\mathrm{f}(x) = 0$, differentiate, then substitute.

Speed

Correct digits roughly double each step near the root.

$\mathrm{f}'(x_0) = 0$

Horizontal tangent β€” the method fails.

$\mathrm{f}'(x_0) \approx 0$

$x_1$ is thrown far away, maybe to another root.

Radians

Essential when $\mathrm{f}$ involves trigonometry.

Confirm

Check the final answer with a change of sign.

6 Practice Questions
Question 1

Use the Newton-Raphson method on $\mathrm{f}(x) = x^2 - 7$ with $x_0 = 3$ to find $x_1$ and $x_2$, and compare with $\sqrt7$.

β–Ά Show solution

$\mathrm{f}'(x) = 2x$. $x_1 = 3 - \dfrac{2}{6} = 2.6667$ (4 d.p.).

$x_2 = 2.6667 - \dfrac{2.6667^2 - 7}{2 \times 2.6667} = 2.6458$ (4 d.p.; exactly $\tfrac{127}{48}$).

$\sqrt7 = 2.64575\ldots$, so $x_2$ is correct to $3$ d.p. already.

Question 2

$\mathrm{f}(x) = x^3 - 5x + 1$. Use the Newton-Raphson method with $x_0 = 2$ to find the root near $2$ correct to $4$ decimal places.

β–Ά Show solution

$\mathrm{f}'(x) = 3x^2 - 5$.

$x_1 = 2 - \dfrac{-1}{7} = 2.142857\ldots$

$x_2 = 2.128571\ldots$,  $x_3 = 2.128419\ldots$,  $x_4 = 2.128419\ldots$

Root $= 2.1284$ to $4$ d.p.

Question 3

Solve $x = \cos x$ using the Newton-Raphson method with $x_0 = 1$, giving the root to $3$ decimal places.

β–Ά Show solution

$\mathrm{f}(x) = x - \cos x$, $\mathrm{f}'(x) = 1 + \sin x$ (radians).

$x_1 = 1 - \dfrac{1 - \cos 1}{1 + \sin 1} = 0.75036\ldots$

$x_2 = 0.73911\ldots$,  $x_3 = 0.73909\ldots$

Root $= 0.739$ to $3$ d.p. (Check: $\mathrm{f}(0.7385) = -0.00098 < 0$, $\mathrm{f}(0.7395) = 0.00069 > 0$.)

Compare Question 5 on the Iteration page: $x_{n+1} = \cos x_n$ needs more than ten steps for the same accuracy.

Question 4

Show that applying the Newton-Raphson method to $\mathrm{f}(x) = x^2 - a$ (with $a > 0$) gives $x_{n+1} = \dfrac12\left(x_n + \dfrac{a}{x_n}\right)$. Use it with $a = 10$ and $x_0 = 3$ to find $x_2$.

β–Ά Show solution

$x_{n+1} = x_n - \dfrac{x_n^2 - a}{2x_n} = \dfrac{2x_n^2 - x_n^2 + a}{2x_n} = \dfrac{x_n^2 + a}{2x_n} = \dfrac12\left(x_n + \dfrac{a}{x_n}\right)$.

$x_1 = \tfrac12(3 + \tfrac{10}{3}) = 3.16667$,  $x_2 = \tfrac12(3.16667 + \tfrac{10}{3.16667}) = 3.16228$.

($\sqrt{10} = 3.162277\ldots$)

Question 5

Use the Newton-Raphson method with $x_0 = 0$ to find the smaller root of $\mathrm{e}^x = 3x$ to $3$ d.p.

β–Ά Show solution

$\mathrm{f}(x) = \mathrm{e}^x - 3x$, $\mathrm{f}'(x) = \mathrm{e}^x - 3$.

$x_1 = 0.5$, $x_2 = 0.6101$, $x_3 = 0.6190$, $x_4 = 0.6191$.

Root $= 0.619$ to $3$ d.p.

Question 6

$\mathrm{f}(x) = \ln x + x - 3$. (a) Use the Newton-Raphson method with $x_0 = 2$ to find $x_1$ and $x_2$. (b) Show that the root is $2.208$ to $3$ d.p.

β–Ά Show solution

(a) $\mathrm{f}'(x) = \dfrac1x + 1$. $x_1 = 2 - \dfrac{\ln 2 - 1}{1.5} = 2.20457\ldots$,  $x_2 = 2.20794\ldots$

(b) $\mathrm{f}(2.2075) = -0.000639\ldots < 0$ and $\mathrm{f}(2.2085) = 0.000814\ldots > 0$. Change of sign, $\mathrm{f}$ continuous for $x > 0$, so the root is $2.208$ to $3$ d.p.

Question 7

Explain why the Newton-Raphson method cannot be used to solve $x^3 - 3x + 1 = 0$ with starting value $x_0 = -1$.

β–Ά Show solution

$\mathrm{f}'(x) = 3x^2 - 3$, so $\mathrm{f}'(-1) = 0$. There is a stationary point (a maximum) at $x = -1$, the tangent there is horizontal and never meets the $x$-axis, and the formula would require division by zero.

Question 8

Show that the Newton-Raphson method applied to $\mathrm{f}(x) = x^3 - 2x + 2$ with $x_0 = 1$ produces a repeating sequence, and suggest a better starting value.

β–Ά Show solution

$\mathrm{f}'(x) = 3x^2 - 2$. $x_1 = 1 - \dfrac{1}{1} = 0$, then $x_2 = 0 - \dfrac{2}{-2} = 1$, and so on: $1, 0, 1, 0, \ldots$

$\mathrm{f}(-2) = -2$ and $\mathrm{f}(-1) = 3$, so there is a root with $-2 < x < -1$; starting at $x_0 = -2$ gives $-1.8,\ -1.7699,\ -1.7693, \ldots$ which converges.

Question 9

By drawing a sketch, explain why the Newton-Raphson method applied to $\mathrm{f}(x) = x^3 - 3x + 1$ with $x_0 = 0.95$ does not converge to the root near $0.35$.

β–Ά Show solution

The curve has a minimum at $x = 1$, so at $x = 0.95$ the gradient is small: $\mathrm{f}'(0.95) = -0.2925$.

The tangent there is almost horizontal and meets the $x$-axis far away, at $x_1 = -2.44$. From there the iterations converge to the root near $-1.88$ (see the diagram in Section 4). Starting at $x_0 = 0.5$ instead gives $0.3333,\ 0.3472,\ 0.3473$, the root required.

Question 10

An open box is made from a $20$ cm by $20$ cm square of card by cutting a square of side $x$ cm from each corner and folding up the sides. The volume must be $500$ cm$^3$.

(a) Show that $x^3 - 20x^2 + 100x - 125 = 0$.
(b) Verify that $x = 5$ is a root.
(c) Use the Newton-Raphson method with $x_0 = 1.5$ to find the other possible value of $x$ to $3$ d.p.
(d) Explain why $x_0 = \tfrac{10}{3}$ would be a bad starting value, and interpret $x = \tfrac{10}{3}$ in context.

β–Ά Show solution

(a) The base is $(20 - 2x)$ by $(20 - 2x)$ and the height $x$: $V = x(20 - 2x)^2 = 4x^3 - 80x^2 + 400x$. Setting $V = 500$ and dividing by $4$: $x^3 - 20x^2 + 100x - 125 = 0$.

(b) $125 - 500 + 500 - 125 = 0$ βœ“

(c) $\mathrm{f}'(x) = 3x^2 - 40x + 100$.

$x_1 = 1.5 - \dfrac{\mathrm{f}(1.5)}{\mathrm{f}'(1.5)} = 1.5 - \dfrac{-16.625}{46.75} = 1.85561\ldots$

$x_2 = 1.90866\ldots$,  $x_3 = 1.90983\ldots$,  $x_4 = 1.90983\ldots$

$x = 1.910$ cm to $3$ d.p. (In fact $x = \tfrac{15 - 5\sqrt5}{2}$ exactly, from the quadratic factor $x^2 - 15x + 25$.)

(d) $\mathrm{f}'\!\left(\tfrac{10}{3}\right) = \tfrac{100}{3} - \tfrac{400}{3} + 100 = 0$, so the formula would divide by zero. Starting close to it fails too: $x_0 = 3.3$ gives $x_1 \approx -31.2$, a meaningless negative length.

In context, $x = \tfrac{10}{3}$ is the stationary point of the volume: it gives the maximum possible volume, $\tfrac{16000}{27} \approx 593$ cm$^3$.

The Newton-Raphson Method · A Level Maths Year 2 · Created with MathJax