Newton–Raphson method

Problem: x_{n+1} = x_n − f(x_n)/f′(x_n) to solve f(x)=0

Provide f(x) (and optionally f′(x)), an initial guess x₀, tolerance ε, and max iterations N. The page computes the iterate, explains why Newton works (and when it fails), and verifies convergence with a test harness.

Input

N is the maximum number of iterations. If f′(x) is omitted, a centered finite‑difference derivative is used. Convergence is declared when both the step size and the residual are ≤ ε (scaled by magnitude). Supported syntax: numbers, x, operators + - * / ^, parentheses, and functions sin, cos, tan, asin, acos, atan, exp, log (ln), log10, sqrt, cbrt, abs, floor, ceil, round; constants pi, e.

Output

Approximate root
Residual |f(x*)|
Iterations
Observed rate
Derivative used
Status
Show iterates
#xf(x)f′(x)|Δx|

Reason Why

Derivation. Taylor at x_n yields 0 = f(x_n)+f′(x_n)(r−x_n)+O((r−x_n)^2); solving gives r ≈ x_n − f(x_n)/f′(x_n).
Quadratic convergence. For a simple root r with f′(r)≠0, e_{n+1} ≈ (f''(r)/(2f'(r)))·e_n^2; digits roughly double each step.
Failure modes. Small/zero f′, poor starting points, or multiple roots reduce/diverge. Damping/backtracking helps.

Check (harness)

Preloaded Checks (harness)

Each block runs Newton and reports the approximate root, residual, iterations, status, and observed rate. Some cases are intentionally tricky.