Newton-Raphson method calculator: every iteration, systems of equations and stiff ODEs

Type f(x), a starting guess and a tolerance: the calculator applies xn+1 = xn − f(xn)/f′(xn) and shows every iteration, the tangent lines and how fast the error falls. cos x = x from x₀ = 1 converges to 0.7390851332 in 4 steps. Derivatives are exact (automatic differentiation), or finite differences if you want to see their error. Free, runs in your browser.

It also solves systems with the Jacobian, finds the optimum relaxation factor, and runs the two Newton-Raphson challenges of Skill-Lync's MATLAB, Python and CFD course: the ice-breaking cushion pressure (one real root per thickness, 4.2391 psf at h = 0.6 ft) and Robertson's stiff kinetics by implicit Euler, where explicit Euler at Δt = 0.1 s blows up at t = 0.2 s. Skill-Lync read 191 public reports on the two: 21 of 94 with code for the ice cubic leave σ = 150 in psi while r and h are in feet.

Burden & Faires §10.2 · Robertson (1966) / Bari IVP test set ROBER · checked against a separate solution (5,244 checks at build) · Updated 23 Nov 2026

A transcendental equation: no closed form, Newton gets 0.7390851332 in a few steps.

Root x*0.7390851332f(x*) = 0
Iterations4converged
f′(x*)−1.67361simple root
−0.5−0.4−0.3−0.2−0.100.70.750.80.850.90.951x₀x₁x₂x₃f(x)blue f(x) · orange tangent at xₙ, meeting the x-axisx
10⁻¹⁰10⁻⁸10⁻⁶10⁻⁴0.01101234|f(xₙ)| (log scale)a straight steepening line = quadraticiteration n
  • Converged in 4 iterations to x = 0.739085133215. Near the root eₙ₊₁/eₙ² settles at 0.221, against |f″/(2f′)| = 0.221: quadratic convergence.

Every iteration

nxₙf(xₙ)f′(xₙ)Δx = −α f/f′|f(xₙ)|eₙ = |xₙ − x*|eₙ₊₁/eₙeₙ₊₁/eₙ²
01−0.4597−1.84147−0.2496360.460.2610.043230.1657
10.75036386784−0.018923−1.6819−0.0112510.01890.01130.0024610.2182
20.739112890911−4.646×10⁻⁵−1.67363−2.776×10⁻⁵4.65×10⁻⁵2.78×10⁻⁵0.0000061290.2208
30.739085133385−2.847×10⁻¹⁰−1.67361−1.701×10⁻¹⁰2.85×10⁻¹⁰1.70×10⁻¹⁰——
40.7390851332150−1.67361—00——

Python and MATLAB code for this f(x)

f′(x) = -sin(x) - 1, differentiated symbolically from your input.

Python
import math

def f(x):
    return math.cos(x) - x

def df(x):  # exact derivative
    return -math.sin(x) - 1

x, alpha, tol = 1, 1, 1e-12
for n in range(1, 51):
    fx = f(x)
    dx = -alpha * fx / df(x)
    x = x + dx
    if abs(f(x)) < tol:
        break
print(n, "iterations, x =", x, "f(x) =", f(x))
MATLAB
f  = @(x) cos(x) - x;
df = @(x) -sin(x) - 1;  % exact derivative
x = 1; alpha = 1; tol = 1e-12;
for n = 1:50
    fx = f(x);
    dx = -alpha * fx / df(x);
    x = x + dx;
    if abs(f(x)) < tol
        break
    end
end
fprintf('%d iterations, x = %.12g, f(x) = %.3g\n', n, x, f(x));

What is the Newton-Raphson method?

A way to solve f(x) = 0 by replacing f with its tangent line at the current guess and jumping to where that line crosses zero. The relaxation factor α scales the jump; α = 1 is the plain method:

For √2, solve x² − 2 = 0 from x₀ = 1:

x₄ is √2 to 12 decimals, and the next step makes |f| = 4×10⁻¹⁶. The calculator draws the tangent of each of the first steps on the plot of f, so you can see why a curve that bends a lot near the start makes the first steps poor.

How fast does Newton-Raphson converge?

Quadratically near a simple root: the error after a step is about a constant times the square of the error before it.

For cos x − x = 0 the root is 0.7390851332, where C = 0.2208. The table's last column, eₙ₊₁/eₙ², goes 0.166, 0.218, 0.221: it settles on C, which is what quadratic means. The plot of log|f| against n bends down more steeply each step instead of falling in a straight line.

Exact derivatives matter less than you might think, but they matter. With a forward difference the slope is wrong by about h·f″/2: the method still converges if the error is small, but more slowly. Switch the derivative to "forward difference" with h = 0.1 to see it.

Why does Newton-Raphson fail, and what can you do?

  • A cycle. x³ − 2x + 2 from x₀ = 0: the tangent at 0 points to 1 and the tangent at 1 points back to 0. The calculator detects the 2-cycle and stops. From x₀ = −2 it converges to −1.7692924 in 4 steps.
  • Running away. atan x from x₀ = 1.5: each tangent overshoots further, and |x| passes 10¹² in 7 steps. From x₀ = 1 it converges in 5. An under-relaxed step (α < 1) or a few bisection steps first fixes this.
  • A flat tangent. If f′(xₙ) = 0 the tangent never meets the axis (x² − 1 from x₀ = 0). Start elsewhere.
  • A multiple root. (x − 1)³ has f′ = 0 at the root itself. Newton still converges, but linearly, with the error multiplied by 2/3 each step: 56 steps to |Δx| < 10⁻¹⁰. With α = 3 (the modified step x − m f/f′ for multiplicity m) it lands on the root in 1. The calculator estimates m from the observed rate and suggests it.
  • Outside the domain. ln(x) − 3 from x₀ = 100 jumps to a negative x, where ln is not defined. The calculator stops with "not a number".

What is the optimum relaxation factor?

At a simple root it is α = 1. Close to the root the error of a relaxed step is

so any α ≠ 1 turns quadratic convergence into linear, and the iteration count rises on both sides of 1. Over α = 0.05 to 1.95, √2 from x₀ = 1 takes the fewest iterations at α = 1 (5); the ice cubic at h = 0.6 ft from p₀ = 10 psf at α = 1 (8 iterations, against 34 at α = 0.5 and 28 at α = 1.5); from p₀ = 100 psf still at α = 1 (15). An "optimum" like 1.05 in a report is the same minimum read off a coarse grid, a different start or a different tolerance: one or two iterations either way.

0204060801000.20.40.60.811.21.41.61.8fewest: 8 at α = 1iterations to converge (gaps: did not converge)relaxation factor α

Why do some reports find an optimum α of 1.5 or more?

Because σ stayed at 150 (psi) and the loop stops on |f(p)| < tol. With σ in psi every coefficient is tiny, and |f| is below 10⁻⁴ for every p from 0 to about 0.03, so the test passes long before the root. From p₀ = 10 with |f| < 10⁻⁴, the sweep's minimum is at α = 1.8 (6 iterations), and the run stops at p = 0.0292 (α = 1 stops at 0.0227). The real root of that cubic is 0.00305: the "optimum α" is measuring how fast the iterate falls into the flat region, not how fast it reaches a root. Convert σ to psf, or stop on |Δp|, and the minimum goes back to α = 1. In the reports: between 0.9 and 1.1, 43 of 59; between 1.1 and 1.3, 7 of 59; at 1.5 or more, 8 of 59.

The exception is a multiple root. For (x − 1)³ the best α in the sweep is 1.95, the edge of the range (23 iterations), because the right value, α = m = 3, is outside it. α between 2 and 3 is "over-relaxation" only in name: it is the multiplicity correction. The verifier confirms the rates |1 − α| for α = 0.25, 0.5, 1.5 and 1.75 and 1 − 1/m for m = 2, 3 and 4.

How does multivariate Newton-Raphson work?

The same tangent idea in n dimensions: linearise every equation at the current point and solve the linear system for the step. The Jacobian takes the place of f′:

This calculator gets J exactly, column by column, with forward-mode automatic differentiation (dual numbers), and solves for Δx by Gaussian elimination with partial pivoting; it never forms J⁻¹. You can switch to a finite-difference Jacobian, which is what most reports code. Burden & Faires' example (section 10.2) is the textbook test:

From (0.1, 0.1, −0.1), with ‖Δx‖∞ < 10⁻⁵, Newton needs 5 iterations to reach (0.5, 0, −0.523598776); the exact solution is (0.5, 0, −π/6). Pick it in the "System of equations" tab to see each iterate and J at the start.

What pressure breaks ice of a given thickness? (the course challenge)

The challenge gives the cushion pressure p needed to break ice of thickness h under an air cushion vehicle as the root of a cubic, and attributes it to Muller ("Ice Breaking with an Air Cushion Vehicle", in Mathematical Modelling: Classroom Notes in Applied Mathematics, SIAM 1987). Skill-Lync could not read that book, so the equation here is the one in the challenge statement:

with b = 0.5, r = 40 ft and s = 150 psi. The units have to agree: with r and h in feet, s must be in pounds per square foot, 150 × 144 = 21,600 psf, and p comes out in psf. For h = 0.6 ft:

That cubic has one real root, p = 4.2390639 psf, and a complex pair 1.0805 ± 0.41212i. Every thickness in the challenge has exactly one real root, so Newton cannot converge to a "wrong" one:

h (ft)p (psf)p (psi)Newton steps from 10 psfs left at 150
0.64.2390640.0294480.003051
1.217.236690.1197140.01514
1.838.990080.2708330.03828
2.469.499280.4826260.07366
3108.76430.7553270.1222
3.6156.78511.089270.1846
4.2213.56181.483110.2617

The last column is what you get if s stays at 150 while r and h are in feet: answers about 1390 times too small at h = 0.6 ft. Typing slips in f(p) move the root, and Newton converges happily to the wrong number. At h = 0.6 ft, leaving 0.4hb² outside the p² bracket gives 4.3708 psf, writing 9r⁶ for 27r⁶ in the constant term gives 4.9774, and dropping the h from 0.4hb² gives 4.1432. The "Check my numbers" tab recognises all three. A slip in f′(p) alone does not move the root, because Newton stops only where f = 0, but it changes the path: keep the constant term in f′(p) with s in psf and Newton from 10 psf never settles (a 2-cycle at h = 0.6 ft; none of the other six thicknesses converges within 100 steps). Only one report's code makes this slip.

Why does the Robertson problem need an implicit method?

The "Multivariate Newton Rhapson Solver" challenge is Robertson's (1966) chemical kinetics, a standard stiff test problem (ROBER in Hairer & Wanner and the Bari test set), with y(0) = (1, 0, 0), run for 10 minutes (600 s):

Explicit Euler is stable only while every eigenvalue λ of the Jacobian ∂f/∂y satisfies

At t = 0 the eigenvalues are 0, 0 and −0.04, so Δt could be 50 s. But y2 builds up within a millisecond, and by t = 0.1 s the fast eigenvalue is −2186.8: Δt must stay below 0.000915 s. At 600 s it is −6158.7, limit 0.000325 s. Explicit Euler with Δt = 0.1 s blows up at t = 0.2 s, with 0.001 s at t = 9.351 s; 0.0005 s survives. Meanwhile the slow part of the solution changes over hundreds of seconds. That mismatch is what "stiff" means.

Backward Euler evaluates f at the new time, so each step is a 3 × 3 nonlinear system, solved by Newton with the Jacobian J = I − Δt ∂f/∂y:

It is stable at any Δt. With Δt = 0.1 s it needs 12,787 Newton iterations over 6,000 steps (2.13 per step) and gives y1(600) = 0.3999758, y2 = 2.632×10⁻⁶, y3 = 0.6000216. The reference solution (scipy Radau, rtol 10⁻¹⁰, which matches the Bari test set's value at t = 10¹¹) is y1 = 0.3999213, y2 = 2.631×10⁻⁶, y3 = 0.6000761. The error in y1 is 1.4×10⁻⁴ relative at Δt = 0.1 s, 1.3×10⁻³ at 1 s and 1.2×10⁻² at 10 s: first order, ten times smaller Δt, ten times smaller error.

y1 + y2 + y3 stays 1 to rounding (3×10⁻¹⁵ over the run), because the three rates add to zero and Newton's step for a linear invariant is exact. A sum that drifts in your results means a sign or a typo in an equation or the Jacobian.

What did 191 student reports find?

Skill-Lync read the text of 191 public reports on the two challenges (95 Breaking Ice, 95 Robertson, 1 other), as of 23 Nov 2026. 5 of them put their results in images with little text, so their numbers are not counted. The counts are Skill-Lync's own data and a starting point, not a grade.

Breaking Ice with Air cushion Vehicle

What the report's text showsReportsNoteExamples
Converted σ to psf (150 × 144 = 21,600) in the code68 of 94 72%Needed because h and r are in feet. This gives p = 4.239 psf at h = 0.6 ft.1, 2, 3
Left σ = 150 (psi) with h and r in feet21 of 94 22%Mixed units. The real root then drops to 0.0031 at h = 0.6 ft, about 1,400 times too small.1, 2, 3
f(p) typed with a slip in the code18 of 94 19%Found by evaluating each f(p) at test points: 7 bracket errors, 7 a wrong constant term (for example 9 r⁶ in place of 27 r⁶), 4 other typos such as a missing h.1, 2, 3
Brackets leave 0.4hβ² outside the p² term7 of 94 7%f(p) then has a different root, 4.3708 at h = 0.6 ft, and two reports typed 4.3708.1, 2, 3
f'(p) matches the exact derivative in the code82 of 94 87%Only 1 kept the constant term in f'(p); 10 had bracket or other typos.1, 2, 3
Typed p = 4.239 psf (0.0294 psi) for h = 0.6 ft20 of 95 21%Matches the real root of the cubic. Most reports show p only in screenshots.1, 2, 3
Typed a p for h = 0.6 ft that is not 4.239 psf12 of 95 13%All but one trace to a slip in that code: σ left in psi (often with an |f| < tol stop far from the root), a bracket error, a wrong constant, a missing h, or α = 2.1, 2, 3
Optimum α stated between 0.9 and 1.143 of 59 73%At a simple root α = 1 keeps Newton's quadratic convergence, so a minimum near 1 is what theory predicts.1, 2, 3
Optimum α stated between 1.1 and 1.37 of 59 12%A start far from the root, judged by iteration count with an |f| < tol stop, can favour α a little above 1.1, 2, 3
Optimum α stated at 1.5 or more8 of 59 14%8 of these kept σ in psi. f is then tiny near p = 0, so |f| < tol is met early after a few large steps, not at the root.1, 2, 3

Week 6 - Multivariate Newton Rhapson Solver

What the report's text showsReportsNoteExamples
Jacobian by finite differences92 of 95 97%As the challenge asks. One more report wrote both an analytic and a numerical Jacobian.1, 2, 3
Residuals f1, f2, f3 in the code match y − y_old − Δt·f(y)79 of 91 87%Checked numerically. 2 had a bracket slip in f2, 1 used ^ for powers (10^4 is 14 in Python), 9 could not be checked from the text.1, 2, 3
Ran to 600 s (10 minutes)85 of 95 89%The challenge says run for 10 minutes of simulated time.1, 2, 3
Ran to an end time other than 600 s8 of 95 8%End times from 10 s, 60 s, 300 s, 500 s, 36,000 s, 120,000 s. Three loop 600 steps whatever Δt; one read 10 minutes as wall-clock time.1, 2, 3
Used Δt = 0.1 s33 of 95 35%The most common choice.1, 2, 3
Used Δt of 1 s or more17 of 95 18%Backward Euler stays stable here; at Δt = 10 s, y1(600 s) is 0.4048 against 0.3999.1, 2, 3
Relaxation factor α = 185 of 95 89%As the challenge asks.1, 2, 3
Typed final y1, y2, y3 at the end time10 of 95 11%8 are within 0.2% of the reference y1(600 s) = 0.39992. The other 2 do not add up to 1.1, 2, 3
Discuss explicit methods in the text but do not run one23 of 95 24%No report runs explicit Euler or a library solver (odeint, solve_ivp, ode15s) in its text.1, 2, 3

Counts as of 23 Nov 2026, n = 191 public reports, from each report's text.

What this calculator does not cover

  • Guaranteed convergence. There is no line search, trust region or bracketing. When Newton cycles or runs away the calculator says so; it does not rescue the run.
  • Complex roots. Iterations are real. The ice tab finds the complex pair of the cubic in closed form, but tab 1 only follows real iterates.
  • Large systems. Up to 4 unknowns with a dense solve. Finite element and CFD codes use sparse factorisations, and often modified Newton or quasi-Newton (BFGS) updates; the explicit vs implicit solver shows those for an FEA load step.
  • Adaptive time steps. The Robertson tab has a fixed Δt or a fixed growth factor. Production stiff solvers (Radau, BDF, CVODE) choose Δt from an error estimate.
Learn numerical methods

Writing your own Newton solver, then a stiff ODE solver around it, is how engineers learn what a CFD or FEA code does at every step. Both challenges here are projects in Skill-Lync's MATLAB, Python and CFD course.

Frequently asked questions

What is the Newton-Raphson method?

A way to solve f(x) = 0 by repeated straight-line guesses. At the current guess, draw the tangent to f and take the point where it crosses the x-axis as the next guess. Near a simple root each step roughly doubles the number of correct digits, so a handful of steps usually gives full precision.

What is the Newton-Raphson formula?

x(n+1) = x(n) − f(x(n)) / f′(x(n)). With a relaxation factor α the step is multiplied by α: x(n+1) = x(n) − α f/f′. For a system F(x) = 0 the division becomes a linear solve with the Jacobian: J Δx = −F, then x(k+1) = x(k) + αΔx.

How do I choose the initial guess?

Start where f changes sign or where a plot of f crosses zero, and away from points where f′ is zero. For engineering problems use a physical estimate: a typical pressure, the previous time step's answer, or a linear approximation. A bad start can cycle, jump to another root or run away.

Why does Newton-Raphson fail or diverge?

Four common reasons: f′ is zero or tiny at an iterate, so the tangent shoots far away; the start is outside the basin of the root (atan x from 1.5); the iterates fall into a cycle (x³ − 2x + 2 from 0); or the function is undefined at a step (a log of a negative number).

What is the order of convergence of Newton-Raphson?

Quadratic, at a simple root with α = 1: the new error is about |f″/(2f′)| times the old error squared. At a root of multiplicity m, or with α ≠ 1, it drops to linear: the error is multiplied by a constant each step, |1 − α/m|.

What is the optimum relaxation factor?

At a simple root, α = 1. Any other α turns quadratic convergence into linear with rate |1 − α|, so the iteration count rises on both sides of 1. A slightly different α can win by one step from a far-away start. At a root of multiplicity m, α = m restores quadratic convergence.

What is the Jacobian in multivariate Newton-Raphson?

The matrix of first partial derivatives J(i, j) = ∂F(i)/∂x(j). It plays the part of f′: each iteration solves J Δx = −F. It can be written out by hand, built by finite differences (one extra F evaluation per column), or computed exactly by automatic differentiation, as this calculator does.

Newton-Raphson vs bisection vs secant: which is better?

Bisection always converges if f changes sign, but only one binary digit per step. Secant needs no derivative and converges with order about 1.62. Newton is fastest, order 2, but needs f′ and a good start. Robust solvers start with bisection and switch to Newton or secant near the root.

Why do stiff ODEs need implicit methods?

In a stiff system some modes decay thousands of times faster than the solution changes. Explicit Euler is stable only if Δt < 2/|λmax|: for Robertson's kinetics that is below 0.001 s. Implicit (backward) Euler is stable for any Δt, but each step is a nonlinear system solved by Newton-Raphson.

Related on Skill-Lync

Sources

  • R. L. Burden and J. D. Faires, Numerical Analysis, chapter 10, section 10.2, Example 1 (Newton's method for the 3 × 3 system from x⁽⁰⁾ = (0.1, 0.1, −0.1), ‖x⁽ᵏ⁾ − x⁽ᵏ⁻¹⁾‖∞ < 10⁻⁵, solution (0.5, 0, −π/6)), as given in H.-Y. Fan's lecture slides, National Taiwan Normal University, 2016.
  • F. Mazzia and C. Magherini, Test Set for Initial Value Problem Solvers, release 2.4, University of Bari and INdAM, 2008: problem ROBER (Robertson 1966; Hairer & Wanner, Solving ODEs II): the equations, k₁ = 0.04, k₂ = 3 × 10⁷, k₃ = 10⁴, y₀ = (1, 0, 0), and the reference solution at t = 10¹¹ (Table II.10.3).
  • The Breaking Ice challenge statement (Skill-Lync course): the cubic, b = 0.5, r = 40 ft, s = 150 psi, h = 0.6 to 4.2 ft. It cites E. R. Muller in Mathematical Modelling: Classroom Notes in Applied Mathematics (ed. M. S. Klamkin, SIAM 1987), which Skill-Lync did not read.
  • Skill-Lync, public reports on the two challenges, read 23 Nov 2026. scripts/verify/newton_raphson.py solves every case another way (hand-written Python expressions with complex-step derivatives, its own Newton loops and Gaussian elimination, numpy.roots and Cardano for the cubic, scipy Radau and BDF for Robertson), 231 cases; the page checks itself against it at build time (5,244 checks).
Free counselling

From a Newton loop to a CFD solver.

Every implicit CFD and FEA code runs Newton-type iterations inside each step. A Skill-Lync counsellor can map the MATLAB, Python or CFD course that fits the role you want.

Talk to a course counsellor

Free. We call you back, usually the same day.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.