Newton-Raphson Method Calculator

Enter a function and a starting guess and this calculator runs Newton-Raphson iteration until the step size falls below your tolerance, printing every iterate, every residual and every step length along the way. The derivative is obtained symbolically from the expression you type, so you do not have to supply it. The iteration table is the point: it shows you the doubling of correct digits that quadratic convergence produces, and it shows you plainly when the method stalls on a flat tangent or wanders away instead.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Function f(x) whose root you wantWrite the equation in the form f(x) = 0. Use * for multiplication and ^ for powers; sin, cos, tan, exp, ln, log, sqrt, asin, acos, atan, sinh, cosh and tanh are available.x^3 - 2*x - 5
Starting guess x0Newton-Raphson is local: start near the root you want, or you may converge to a different one.2
Stop when the step falls belowThe stopping test is on the size of the correction, not on the residual f(x).1e-8
Maximum iterationsA cap so a diverging or cycling iteration terminates. Quadratic convergence rarely needs more than about ten steps from a good guess.25

It returns

  • Root estimate — The last iterate. Trust it only when the iteration converged and the residual below is near zero.
  • Residual f at the estimate
  • Iterations used
  • Final step size
  • Derivative at the estimate
  • Measured convergence order — About 2 at a simple root, about 1 at a repeated root.

The formula

xn+1=xnf(xn)f(xn)
εn+1f(r)2f(r)εn2

In plain text: x_(n+1) = x_n − f(x_n) / f′(x_n)

  • x_nThe current estimate of the root (x-units)
  • f(x_n)The residual — how far the function is from zero there (f-units)
  • f′(x_n)The slope of the tangent at the current estimate (f-units per x-unit)
  • ε_nThe error x_n − r, where r is the true root (x-units)

The update is the x-intercept of the tangent line drawn at the current estimate.

Updated Category Numerical Methods, Root Finding & Interpolation Verified against published test cases Reading time 10 min

What the method actually does

Newton-Raphson replaces a hard problem with an easy one, repeatedly. You cannot solve x3 − 2x − 5 = 0 by rearranging, but you can solve the equation of the tangent line at any point in one line of algebra. So the method draws the tangent to the curve at your current guess, finds where that straight line crosses the x-axis, and calls that the next guess. Repeat.

Writing the tangent at xn as y = f(xn) + f′(xn)(xxn) and setting y = 0 gives the update rule directly: x = xn − f(xn)/f′(xn). Everything else about the method is a consequence of that one line — including its speed and both of its failure modes.

Isaac Newton demonstrated the procedure on this very cubic, x3 − 2x − 5 = 0, which is why it is the default in the box above. Joseph Raphson published the iterative form in 1690 that is closer to what you use today, and Thomas Simpson gave the general derivative-based statement in 1740.

Why the digits double, and when they stop doubling

Expand f about the true root r in a Taylor series and you find that the new error is proportional to the square of the old one: εn+1 ≈ [f″(r)/2f′(r)] εn2. That is what quadratic convergence means in practice — the number of correct decimal places roughly doubles with every step. An error of 10−2 becomes 10−4, then 10−8, then 10−16, which is already at the limit of double precision. Four or five iterations from a decent starting guess is typical, and you can watch it happen in the step column of the table.

The proportionality constant carries f′(r) in the denominator, and that is the whole story of when the method degrades. At a repeated root, f′(r) = 0 and the quadratic term is not available; convergence drops to linear, with the error shrinking by a constant factor of (m−1)/m per step for a root of multiplicity m. For a double root that factor is exactly one half, which you can verify by running x^2 from x0 = 1 and reading the step column: 0.5, 0.25, 0.125, and so on.

The calculator measures this rather than assuming it. It estimates the observed order from the last three step sizes as ln(dn/dn−1) ÷ ln(dn−1/dn−2), which returns about 2 for a simple root and about 1 for a repeated one.

Worked example: solving x³ − 2x − 5 = 0 from x₀ = 2

The derivative is f′(x) = 3x2 − 2. Do the first two steps by hand.

  1. Iteration 0. f(2) = 8 − 4 − 5 = −1. f′(2) = 3(4) − 2 = 10. The correction is −1/10 = −0.1, so x1 = 2 − (−0.1) = 2.1. The step size is 0.1.
  2. Iteration 1. f(2.1) = 9.261 − 4.2 − 5 = 0.061. f′(2.1) = 3(4.41) − 2 = 11.23. The correction is 0.061/11.23 = 0.00543188, so x2 = 2.1 − 0.00543188 = 2.09456812. The step has fallen from 0.1 to 0.0054 — a factor of 18.
  3. Iteration 2. The step falls to about 1.66 × 10−5. Compare that to the square of the previous step, 0.00542 = 2.9 × 10−5: the same order of magnitude, which is quadratic convergence made visible.
  4. Iteration 3. The step falls to about 1.6 × 10−10, below the 10−8 tolerance, so the iteration stops after 4 passes with x = 2.0945514815.

Check the answer by substitution: 2.09455148153 = 9.1891029631, and 2 × 2.0945514815 + 5 = 9.1891029630. The residual is smaller than 10−9.

Now feed the three step sizes 0.00543188, 1.66 × 10−5 and 1.6 × 10−10 into the order estimate: ln(1.6×10−10 / 1.66×10−5) ÷ ln(1.66×10−5 / 0.00543188) = (−11.55) ÷ (−5.79) = 2.0. The method is behaving exactly as the theory says.

How to read the iteration table

The step column is the diagnostic. If each step is roughly the square of the previous one, you are converging quadratically to a simple root and the answer is trustworthy. If each step is a constant fraction of the previous one, you have a repeated root or a shallow crossing; the root is still there but the last few digits are not reliable. If the steps are growing, the iterates are leaving the neighbourhood and the starting guess needs to change.

The residual column is the honesty check. A small step does not by itself prove you have a root. On a stretch where the curve is nearly flat, the correction f/f′ can be small simply because f′ is large, while f is still far from zero. Always read the residual next to the step. The calculator warns you when the steps have stopped but the residual has not.

The derivative column shows you the danger. Values drifting toward zero mean the tangent is flattening, and a flat tangent throws the next iterate a long way off. Exactly zero and the method simply has no next step — the tangent is parallel to the axis it is supposed to cross.

How many iterations is normal? From a starting guess with about one correct digit, expect four to six iterations to reach a tolerance of 10−8, because the correct digits double each pass. Needing twenty steps is a signal, not a nuisance: either the starting guess was far away, or the root is repeated.

How the method behaves on different kinds of root

All figures produced by running this calculator with the tolerance shown. Each row is reproducible by typing the function and starting guess into the box above.
f(x)x₀ToleranceResultIterationsOrder
x³ − 2x − 521e-82.09455148154≈2
x² − 211e-81.41421356245≈2
x² − 612101e-824.73863375376≈2
cos(x) − x11e-100.73908513325not reported
x² (double root)11e-6≈9.5×10⁻⁷20≈1
x² − 401e-8no step — f′(0) = 00

The double-root row is the one worth studying: twenty iterations for six digits, against five iterations for ten digits on the simple root two rows above it. The order estimate needs three successive non-zero steps, so it is not reported when a step lands exactly on zero, as it does for cos(x) − x.

The four ways Newton-Raphson fails

  • Zero derivative. The tangent is horizontal and has no x-intercept, so there is no next iterate at all. The calculator stops and says so. Bisection needs no derivative and is the standard fallback.
  • Convergence to the wrong root. The method is local. A function with several roots hands you whichever one the tangent chain happens to lead to, and that need not be the nearest one to your guess. Sketch the function or bracket the root first.
  • Cycling. Some functions send the iteration into a loop that never settles — the classic example is f(x) = x³ − 2x + 2 started at x₀ = 0, which alternates between 0 and 1 forever. The iteration cap is what saves you.
  • Slow crawl at a repeated root. Convergence becomes linear, and the achievable accuracy is limited: near a double root, f is quadratically flat, so floating-point noise in f masks the root over an interval of width roughly the square root of machine epsilon.
  • Leaving the domain. An iterate that lands where ln(x) or sqrt(x) is undefined ends the run. Restarting closer to the root usually fixes it.

Newton-Raphson is how your computer computes square roots

Applying the method to f(x) = x2a gives xn+1 = xn − (xn2a)/(2xn), which simplifies to the average of xn and a/xn. That is the Babylonian method, known for around 3,700 years and still the basis of the square-root routine in most numerical libraries. Try it: enter x^2 - 612 with a starting guess of 10 and watch it reach 24.7386337537 in six steps.

When to use something else

Use bisection when you need a guarantee. If you can find two points where f has opposite signs, the bisection method cannot fail: the bracket halves every step and the root stays inside it. It is slow — one bit of accuracy per iteration against a doubling of digits — but it never diverges and never needs a derivative. A common professional pattern is bisection to get close, then Newton to finish.

Use the secant method when the derivative is expensive or unavailable. The secant method replaces f′ with the slope through the last two iterates. Its convergence order is the golden ratio, about 1.618, so it needs a few more iterations than Newton but only one function evaluation per step instead of two.

Check whether you need a root-finder at all. A quadratic has a closed-form solution — use the quadratic equation calculator. Polynomial roots can also be read off as the eigenvalues of a companion matrix, which is what the eigenvalue calculator does for the characteristic polynomial.

Newton-Raphson also generalises. In several variables the derivative becomes the Jacobian matrix and the division becomes a linear solve, so each step is a system of equations handled by Gauss-Jordan elimination — the same idea, one dimension up.

Frequently asked questions

Do I have to enter the derivative myself?

No. The calculator parses your expression into a syntax tree and differentiates it symbolically using the product, quotient, power and chain rules, so f′ is exact rather than approximated. The derivative it obtained is shown in the first line of the working. If you enter a function it cannot differentiate, it falls back to a central-difference estimate rather than refusing to run.

How many iterations should Newton-Raphson need?

Four to six from a reasonable starting guess, for a tolerance of 1e-8 at a simple root. Because correct digits roughly double each pass, going from one correct digit to sixteen takes only four steps. If you are seeing fifteen or twenty iterations, either the start was far away or the root is repeated — check the measured convergence order, which drops to about 1 in the repeated case.

Why does it say the derivative is zero and stop?

Because the tangent at that iterate is horizontal, and a horizontal line never crosses the x-axis, so the update formula divides by zero. It is a genuine breakdown of the method, not a rounding problem. Move the starting guess to one side — for x² − 4, starting at 1 or at 3 works immediately, while starting exactly at 0 cannot.

The step size is tiny but f is not near zero. What happened?

You are on a nearly flat part of the curve where the derivative is large, so the correction f/f′ is small even though f itself is not. The stopping test on step size has been satisfied without a root being found. Read the residual output, tighten the tolerance, or restart from a point closer to where the curve actually crosses.

Can Newton-Raphson find complex roots?

Not from a real starting guess, and not in this calculator, which works entirely in real arithmetic. Started from a real number, every iterate stays real, so a polynomial such as x² + 1 with no real root simply wanders. The method does work in the complex plane with a complex starting value, which is how Newton fractals are generated, but that is a different tool.

What tolerance should I choose?

1e-8 is a sensible default for double-precision work and is what the calculator starts with. Tightening to 1e-12 costs at most one extra iteration at a simple root, because the digits double. At a repeated root a tight tolerance may never be reachable at all, since floating-point noise in f swamps the root over a small interval; loosen it and read the residual instead.

Does the method work for equations that are not written as f(x) = 0?

Rearrange first. To solve cos(x) = x, enter cos(x) - x, whose root at 0.7390851332 is the value where the two sides meet. Any equation g(x) = h(x) becomes the root problem g(x) − h(x) = 0, and the geometry is the same: you are looking for where two curves intersect.

Why is my root different from someone else's for the same function?

Most likely you started from different guesses and converged to different roots. A cubic can have three real roots, and Newton-Raphson gives you whichever one the tangent chain leads to — which is not always the closest to where you started. The basins of attraction of the different roots interleave in a complicated way. Bracket the root you want first if it matters.

References

  • Numerical Analysis, 10th ed., chapter 2 (Solutions of Equations in One Variable) — Richard L. Burden and J. Douglas Faires, Cengage Learning
  • Numerical Recipes: The Art of Scientific Computing, 3rd ed., §9.4 Newton-Raphson Method Using Derivative — Press, Teukolsky, Vetterling and Flannery, Cambridge University Press
  • NIST Digital Library of Mathematical Functions, §3.8 Nonlinear EquationsNational Institute of Standards and Technology