Newton's Method for a Root
Find where a function crosses zero by repeatedly following its tangent line, and watch the error square each step.
The iteration
To solve f(x) = 0, Newton's method uses the update x_new = x - f(x)/f'(x): step to where the tangent at the current point hits the axis. Near a simple root it converges quadratically - the number of correct digits roughly doubles each iteration.
Worked example: square root of 2
Solve f(x) = x^2 - 2 = 0. The update becomes x_new = x - (x^2-2)/(2x) = (x + 2/x)/2, the ancient Babylonian square-root iteration.
def newton(f,df,x,tol=1e-12):
for i in range(50):
fx=f(x)
if abs(fx)<tol: break
x=x-fx/df(x)
return x,i
x,it=newton(lambda x:x*x-2, lambda x:2*x, 1.0)
print(x,'in',it,'iterations') # 1.41421356... in ~5
Convergence
Starting from x=1: 1.5, 1.41667, 1.414216, then correct to machine precision - the error goes 0.08, 0.006, 0.00002, showing the quadratic doubling of digits. Few methods match this speed when they apply.
Failure modes
Newton needs the derivative and a decent starting guess. It can overshoot, cycle, or diverge if f'(x) is near zero, if the root is a multiple root (then convergence drops to linear), or if the start is far from any root. Safeguarded variants fall back to bisection when a Newton step misbehaves, combining speed with guaranteed convergence.