TExcelTAD
Home › Numerical Methods › The Secant Method and Convergence Rates

The Secant Method

Newton's method needs f′f', which may be unavailable, expensive, or buried in a black-box simulation. The secant method replaces the tangent by the line through the last two iterates. It needs only one new function value per step and still converges superlinearly.

The iteration

The secant line through (xk−1,f(xk−1))(x_{k-1}, f(x_{k-1})) and (xk,f(xk))(x_k, f(x_k)) crosses zero at

xk+1=xk−f(xk) xk−xk−1f(xk)−f(xk−1).x_{k+1} = x_k - f(x_k)\,\frac{x_k - x_{k-1}}{f(x_k) - f(x_{k-1})}.

It is Newton's method with f′(xk)f'(x_k) replaced by the difference quotient.

python · try it yourself
import numpy as np

def secant(f, x0, x1, tol=1e-14, maxit=50):
    f0, f1 = f(x0), f(x1)
    hist = [x0, x1]
    for _ in range(maxit):
        x2 = x1 - f1 * (x1 - x0) / (f1 - f0)
        hist.append(x2)
        if abs(x2 - x1) < tol * max(1, abs(x2)):
            break
        x0, f0, x1, f1 = x1, f1, x2, f(x2)
    return x2, hist

f = lambda x: x * np.exp(x) - 2
r, hist = secant(f, 0.0, 1.0)
err = np.abs(np.array(hist) - r)
for k, e in enumerate(err[:-1]):
    print(f"k = {k}: error {e:.2e}")
k = 0: error 8.53e-01
k = 1: error 1.47e-01
k = 2: error 1.17e-01
k = 3: error 1.31e-02
k = 4: error 1.23e-03
k = 5: error 1.24e-05
k = 6: error 1.17e-08
k = 7: error 1.12e-13
k = 8: error 0.00e+00

Order of convergence

Analysis gives ϵk+1≈Cϵkϵk−1\epsilon_{k+1} \approx C\epsilon_k\epsilon_{k-1}. Trying ∣ϵk+1∣≈A∣ϵk∣q\lvert\epsilon_{k+1}\rvert \approx A\lvert\epsilon_k\rvert^q leads to q2=q+1q^2 = q + 1, so

q=1+52≈1.618,q = \frac{1 + \sqrt{5}}{2} \approx 1.618,

the golden ratio. Per step this is slower than Newton's q=2q = 2, but each secant step costs one function evaluation while a Newton step costs ff and f′f'. If f′f' costs as much as ff, two secant steps (order 1.6182≈2.621.618^2 \approx 2.62) cost the same as one Newton step, so the secant method is often faster in practice.

In double precision the method converges in so few steps that the order is hard to read off the errors. With 300-digit arithmetic from mpmath the pattern is clear:

python · try it yourself
import mpmath as mp

mp.mp.dps = 300
f = lambda x: x * mp.exp(x) - 2
r = mp.findroot(f, 0.85)
x0, x1 = mp.mpf(0), mp.mpf(1)
errs = [abs(x0 - r), abs(x1 - r)]
for _ in range(11):
    x0, x1 = x1, x1 - f(x1) * (x1 - x0) / (f(x1) - f(x0))
    errs.append(abs(x1 - r))
L = [mp.log(e) for e in errs]
orders = [(L[k + 1] - L[k]) / (L[k] - L[k - 1]) for k in range(4, 12)]
print("errors:", [mp.nstr(e, 2) for e in errs[4:]])
print("estimated orders:", [mp.nstr(q, 4) for q in orders])
errors: ['0.0012', '1.2e-5', '1.2e-8', '1.1e-13', '1.0e-21', '8.7e-35', '6.8e-56', '4.5e-90', '2.4e-145']
estimated orders: ['1.941', '1.516', '1.66', '1.603', '1.624', '1.616', '1.619', '1.618']

Inverse interpolation

Instead of fitting a line y=p(x)y = p(x) through the last points and solving p(x)=0p(x) = 0, one can fit xx as a function of yy and evaluate it at y=0y = 0. With three points this is inverse quadratic interpolation (order about 1.841.84), used inside Brent's method together with bisection (Rootfinding in Practice).

Weaknesses

  • Like Newton, it can diverge from a poor start, and it does not keep a bracket.
  • When f(xk)≈f(xk−1)f(x_k) \approx f(x_{k-1}) the division is unstable; implementations stop when the step is tiny.
  • Regula falsi (false position) keeps a bracket by always using the two points with opposite signs, but it can stall with one endpoint stuck, giving only linear convergence. Variants such as the Illinois method fix that.

In software

  • scipy.optimize.newton(f, x0) without fprime uses the secant method; root_scalar(f, x0=..., x1=..., method="secant") too.
  • Excel's IRR and RATE use secant-like iterations from a default guess, which is why they sometimes report #NUM! and accept a better guess as an argument.

Exercises

Exercise 1: One step by hand

Do one secant step for f(x)=x2−2f(x) = x^2 - 2 with x0=1x_0 = 1, x1=2x_1 = 2.

Answer

x2=43x_2 = \frac{4}{3}.

Solution

f(1)=−1f(1) = -1, f(2)=2f(2) = 2: x2=2−2⋅2−12−(−1)=2−23=43x_2 = 2 - 2\cdot\frac{2 - 1}{2 - (-1)} = 2 - \frac{2}{3} = \frac{4}{3}.

Exercise 2: Efficiency index

The efficiency of a method with order qq and mm evaluations per step is q1/mq^{1/m}. Compare Newton (q=2q = 2, m=2m = 2) and secant.

Answer

Newton 2≈1.414\sqrt{2} \approx 1.414; secant 1.6181.618.

Solution

The efficiency index is the order per function evaluation; the secant method wins when f′f' costs as much as ff.

Exercise 3: Regula falsi stalls (code)

Run 20 steps of regula falsi (keep the bracket) for f(x)=x10−1f(x) = x^{10} - 1 on [0,1.3][0, 1.3] and compare with brentq on the same bracket.

Answer

Regula falsi is still off by about 0.0450.045 after 20 steps (the right endpoint never moves); brentq reaches an error of about 10−1310^{-13} (its default tolerance) in 10 function calls.

Solution
python · try it yourself
from scipy.optimize import brentq
f = lambda x: x**10 - 1
a, b = 0.0, 1.3
for _ in range(20):
    c = b - f(b) * (b - a) / (f(b) - f(a))
    if f(a) * f(c) < 0:
        b = c
    else:
        a = c
r, info = brentq(f, 0.0, 1.3, full_output=True)
print(f"regula falsi: error {abs(c - 1):.2e}, right end still {b}")
print(f"brentq: error {abs(r - 1):.1e} after {info.function_calls} calls")
regula falsi: error 4.47e-02, right end still 1.3
brentq: error 1.5e-13 after 10 calls

Test yourself

The secant method's order of convergence is about…

  1. 1
  2. 1.618
  3. 2
  4. 3

Why can the secant method beat Newton in run time?

  1. It has higher order
  2. It needs only one function evaluation per step and no derivative
  3. It always brackets the root
  4. It uses less memory

How many starting values does the secant method need?

  1. 1
  2. 2
  3. 3
  4. none