Computing Library › Worked Examples
Worked Examples

The Secant Method

Get near-Newton speed without computing a derivative by approximating the slope from two recent points.

Newton without the derivative

When f'(x) is unavailable or expensive, replace it with the finite-difference slope through the two most recent iterates. The secant update is x_new = x1 - f(x1)*(x1 - x0)/(f(x1) - f(x0)).

python
def secant(f,x0,x1,tol=1e-12):
    for i in range(50):
        f0,f1=f(x0),f(x1)
        if abs(f1)<tol: break
        x0,x1=x1, x1-f1*(x1-x0)/(f1-f0)
    return x1,i
print(secant(lambda x:x*x-2,1.0,2.0))  # 1.41421356...
Kronos motion — speed accuracy

Convergence order

The secant method converges with order phi = 1.618, the golden ratio - superlinear, between bisection's linear and Newton's quadratic. Since it needs only one new function evaluation per step (versus Newton's function plus derivative), it is often more efficient per unit work when derivatives are costly.

Trade-offs

Like Newton, the secant method has no bracket guarantee: it can diverge on a bad pair of starting points, and it fails if two successive f-values are equal (a flat secant). It also does not require the two starting points to bracket the root. When robustness matters, the safeguarded false-position and Brent methods blend the secant's speed with a maintained bracket.

When to reach for it

Choose the secant method for smooth scalar equations where the derivative is awkward to code or expensive to evaluate, and you have a reasonable starting neighbourhood - a common situation in physics parameter fits.