MathsCalculus

Newton's Method
calculator.

Find where f(x) reaches 0 by following tangent lines down from a starting guess.

How it's worked out

Newton's method, also called Newton-Raphson, replaces a curve with its tangent line. The tangent is easy to solve, so you jump to where it crosses the x-axis, and that crossing becomes your next guess. Repeat it until the guesses stop moving.

xn+1\displaystyle x_{n+1}=xn−f(xn)f′(xn)\displaystyle {}= x_n - \frac{f(x_n)}{f'(x_n)}

The formula comes straight from the tangent line. At xnx_n the line has height f(xn)f(x_n) and slope f′(xn)f'(x_n). Set its height to 0, solve for x, and you get the step above. The tool differentiates your formula with exact rules, so each slope is as good as the arithmetic allows.

To solve an equation with something on both sides, move it all to one side first. For cos x = x you enter cos x − x. The search stops when a step is smaller than your tolerance, scaled by the size of x once x is above 1. It also stops at the step limit, on a flat tangent, on a repeat of an earlier value, or when the values run away.

Near a simple root, the error is roughly squared at each step, so the number of correct digits about doubles. That is called quadratic convergence, and a simple root is one where the slope is not 0. The observed order is measured from your last three step sizes.

Worked examples

Priya works out the square root of 2 by hand

Priya wants √2 with no square root key. She solves x² − 2 = 0 from x₀ = 1. The first steps give 1.5, 1.4166666667, 1.4142156863, 1.4142135624.

The step sizes are 0.5, 0.083333, 0.002451, 0.000002. You can watch the correct digits double, and the search settles after 6 steps at 1.41421356237.

Open this example in the tool

Lena finds all three crossings of a cubic

Lena has f(x) = x³ − 3x + 1 from her textbook. A sketch shows a crossing between 1 and 2, so she starts at 2. The guesses run 1.666666667, 1.548611111, 1.532390162, 1.532088989, and they settle at 1.532088886.

One start finds one root. From 0 she reaches 0.347296, and from −2 she reaches −1.879385. That gives her all three, since a cubic has at most three real roots.

Open this example in the tool

Ben hits a start that loops forever

Ben tries x³ − 2x + 2 from 0. The values go 0, 1, 0, 1 and then repeat, so the tool reports a cycle and gives no root.

The function does have a real root, and a better start finds it. From −2 the method settles at −1.769292 in 5 steps. When you hit a loop, change the start and do not raise the step limit.

Open this example in the tool

Reading your result

The observed order. A figure near 2 means quadratic convergence at a simple root. Near 1 means slow, steady progress, which points to a repeated root. Near 3 can happen when the second derivative is also 0 at the root, as it is for arctan x at 0.

A repeated root. With (x−r)m(x - r)^m, one step removes exactly 1m\frac{1}{m} of the distance to r. So (x − 1)² only halves the gap each time, and it takes 40 steps from 2. The tool estimates the multiplicity m, here 2, and you can multiply each step by m to bring the speed back. That is more than the default limit of 30 steps, so raise the limit for a root like this.

The last step size. Once steps are tiny, the size of the last one is a good cap on the remaining error at a simple root. The check in the working then puts the root back into f and looks at the sign either side. A sign change shows a true crossing. No change means the curve only touches the axis.

Common mistakes

  • Starting too far out on a curve that flattens. For arctan x the root is 0. From 1.3 the method reaches 0, but from 1.5 each tangent overshoots further: 1.5, −1.69, 2.32, −5.11, and then it runs away.
  • Starting at a turning point. There the tangent is flat and never meets the axis, and the formula would divide by 0. Move the start a little to either side.
  • Assuming you got the root you wanted. With several roots, a start can jump past the nearest one. The table of other starts shows which root each one reaches.
  • Entering an equation without moving everything to one side. The method finds where f is 0, so g(x) = h(x) must go in as g(x) − h(x).

Questions people ask

Sketch f, or find two x values where f has opposite signs, and start between them. Try to stay on a stretch that keeps rising or falling, with no turning point between your start and the root. If a start fails, moving it is usually the fastest fix.

Sources