DEV Community

Cover image for The Newton-Raphson Method: Finding Roots by Following the Tangent
NovaSolver
NovaSolver

Posted on • Originally published at novasolver.jp

The Newton-Raphson Method: Finding Roots by Following the Tangent

Most equations you meet in engineering cannot be solved with algebra. A pump curve crossing a system curve, the temperature where two heat-transfer terms balance, the angle that satisfies a kinematic loop — none of these rearranges into a clean closed-form answer. What you can almost always do is write the problem as f(x) = 0 and then hunt for the value of x that makes it true. The Newton-Raphson method is the fastest widely used way to do that hunt.

This article explains how the method works, walks through computing the square root of two by hand, and lists the situations where this otherwise excellent algorithm quietly fails.

Why this calculation matters

Root-finding is everywhere once you start looking. Solving a nonlinear circuit, finding the internal rate of return on a cash flow, locating an equilibrium point, inverting a calibration curve — all of them reduce to "find x such that f(x) = 0." Newton-Raphson is the workhorse behind a great deal of this. It is built into calculators, spreadsheet solvers, and the inner loop of nearly every nonlinear finite-element and circuit simulator.

Its appeal is speed. When it works, Newton-Raphson converges quadratically: the number of correct digits roughly doubles with each iteration. A method that gives you two correct digits after one step can give you eight after three. For an inner loop that may run millions of times inside a larger simulation, that speed is the difference between a calculation that finishes and one that does not. Understanding the method also means understanding when to distrust it, which is just as valuable.

The core method

Newton-Raphson is built on one geometric idea: near a root, a smooth curve looks almost straight. So instead of solving the hard nonlinear equation, you replace the function with its tangent line at your current guess and solve that — which is trivial.

Start at a guess x_n. Draw the tangent to the curve f at that point; its slope is the derivative f'(x_n). Follow that tangent down to where it crosses the x-axis. That crossing point is your next, better guess. Writing out the geometry gives the iteration formula:

x_{n+1} = x_n - f(x_n) / f'(x_n)
Enter fullscreen mode Exit fullscreen mode

You repeat until f(x) is acceptably close to zero, or until two successive guesses barely differ. Each pass needs one function value and one derivative value.

The payoff is the convergence rate. For a simple root with a well-behaved function, the error after a step is proportional to the square of the error before it:

error_{n+1}  is proportional to  (error_n)^2
Enter fullscreen mode Exit fullscreen mode

That is what quadratic convergence means in practice: an error of 0.01 becomes about 0.0001, then about 1e-8. The number of correct digits roughly doubles each iteration. No method that uses only function evaluations does much better near a clean root — which is why Newton-Raphson is the default rather than the fallback.

A worked example

Suppose you want sqrt(2) but only have the four arithmetic operations. Turn it into a root-finding problem: sqrt(2) is the positive solution of

f(x) = x^2 - 2 = 0       with derivative   f'(x) = 2x
Enter fullscreen mode Exit fullscreen mode

The Newton iteration for this function becomes x_{n+1} = x_n - (x_n^2 - 2) / (2*x_n).

Start with x0 = 1.5, a rough first guess.

Step 1 — first iteration.

x1 = 1.5 - (1.5^2 - 2) / (2 * 1.5)
x1 = 1.5 - (2.25 - 2) / 3
x1 = 1.5 - 0.25 / 3
x1 = 1.41667
Enter fullscreen mode Exit fullscreen mode

Step 2 — second iteration. Feed x1 back in:

x2 = 1.41667 - (1.41667^2 - 2) / (2 * 1.41667)
x2 = 1.41667 - 0.006946 / 2.83333
x2 = 1.41422
Enter fullscreen mode Exit fullscreen mode

The true value is sqrt(2) = 1.41421. After just two iterations the result matches it to five digits. Notice the pace: the first guess was off by about 0.085, the second by about 0.0025, the third by under 0.00001. Each step roughly doubled the number of correct digits — exactly the quadratic convergence the theory promises. A third iteration would pin down the answer to roughly ten digits.

Common mistakes

A zero or near-zero derivative. The formula divides by f'(x_n). If the tangent is flat, the next guess is thrown far away or the method fails outright. Roots at a local maximum or minimum of f, and inflection regions, are danger zones.

Assuming convergence is guaranteed. The fast quadratic behavior is only local — it holds near the root. From a poor starting guess the iteration can overshoot, oscillate between values, or wander off to a different root entirely. A good initial guess matters more than for slower, more robust methods.

Trusting it on multiple roots. When the root is repeated — the curve touches the axis instead of crossing it cleanly — the quadratic convergence degrades to merely linear. The method still works but loses its main advantage, and a naive convergence test may stop too early.

Recomputing the derivative carelessly. Newton-Raphson needs f'(x), and if the derivative is wrong, the method converges to the wrong answer or not at all. When an analytic derivative is unavailable, a finite-difference approximation introduces its own error and slows convergence.

Stopping on the step size alone. Two successive guesses being close does not always mean f(x) is small — it can also mean the iteration has stalled on a near-flat region. A reliable stopping rule checks both the change in x and the residual f(x).

Try the interactive NovaSolver calculator

Working two iterations by hand makes the idea clear, but seeing the tangent lines march toward the root makes it stick. The Newton-Raphson Simulator on NovaSolver visualizes the iteration on a nonlinear function, drawing each tangent line and plotting the log-scale error curve so you can watch the digits double. You can set the starting guess, the maximum iteration count, and the convergence tolerance, and even tune a relaxation factor to see how it changes the path to the root — a hands-on way to feel both the speed and the fragility of the method.

Related calculators

  • Bisection Method Calculator — the slow but guaranteed alternative, useful when Newton-Raphson is too fragile or the derivative is unavailable.
  • Gauss Quadrature Calculator — for the companion numerical task of evaluating integrals accurately with few sample points.
  • Gauss-Seidel Solver — an iterative method for the linear systems that often appear inside each Newton step of larger problems.

You can browse the full set in the numerical methods and mathematics tools hub.

Closing note

The Newton-Raphson method is a small, elegant loop that solves equations algebra cannot touch. The key ideas are worth carrying: replace the curve with its tangent, follow it to the axis, repeat, and watch the accuracy square itself each step. But the same loop demands respect — a flat derivative, a bad starting guess, or a repeated root will all break the magic. Pair it with a reliable stopping test, keep a robust fallback like bisection in reserve, and Newton-Raphson becomes one of the most dependable tools in numerical computing.

Top comments (0)