In numerical analysis, the secant method is a root-finding algorithm that uses a succession of roots of secant lines to better approximate a root of a function f. The secant method can be thought of as a finite-difference approximation of Newton's method, so it is considered a quasi-Newton method. Historically, it is as an evolution of the method of false position, which predates Newton's method by over 3000 years.[1]
The secant method is an iterative numerical method for finding a zero of a function . Given two initial values and, the method proceeds according to the recurrence relation
xn =xn-1-f(xn-1)
xn-1-xn-2 | |
f(xn-1)-f(xn-2) |
=
xn-2f(xn-1)-xn-1f(xn-2) | |
f(xn-1)-f(xn-2) |
.
This is a nonlinear second-order recurrence that is well-defined given and the two initial values and . Ideally, the initial values should be chosen close to the desired zero.
Starting with initial values and, we construct a line through the points and, as shown in the picture above. In slope–intercept form, the equation of this line is
y=
f(x1)-f(x0) | |
x1-x0 |
(x-x1)+f(x1).
x=x1-f(x1)
x1-x0 | |
f(x1)-f(x0) |
.
We then use this new value of as and repeat the process, using and instead of and . We continue this process, solving for,, etc., until we reach a sufficiently high level of precision (a sufficiently small difference between and):
\begin{align} x2&=x1-f(x1)
x1-x0 | |
f(x1)-f(x0) |
,\\[6pt] x3&=x2-f(x2)
x2-x1 | |
f(x2)-f(x1) |
,\\[6pt] &\vdots\\[6pt] xn&=xn-1-f(xn-1)
xn-1-xn-2 | |
f(xn-1)-f(xn-2) |
. \end{align}
The iterates
xn
f
x0
x1
f
f
\varphi=(1+\sqrt{5})/2 ≈ 1.618.
If the initial values are not close enough to the root or
f
f
f'=0
The secant method does not require or guarantee that the root remains bracketed by sequential iterates, like the bisection method does, and hence it does not always converge. The false position method (or Latin: regula falsi) uses the same formula as the secant method. However, it does not apply the formula on
xn-1
xn-2
xn-1
xk
f(xk)
f(xn-1)
The recurrence formula of the secant method can be derived from the formula for Newton's method
xn=xn-1-
f(xn-1) | |
f'(xn-1) |
\epsilon=xn-1-xn-2
f'(xn-1)=\lim\epsilon
f(xn-1)-f(xn-1-\epsilon) | |
\epsilon |
≈
f(xn-1)-f(xn-2) | |
xn-1-xn-2 |
The secant method can be interpreted as a method in which the derivative is replaced by an approximation and is thus a quasi-Newton method.
If we compare Newton's method with the secant method, we see that Newton's method converges faster (order 2 against order the golden ratio φ ≈ 1.6). However, Newton's method requires the evaluation of both
f
f'
f
f
Broyden's method is a generalization of the secant method to more than one dimension.
The following graph shows the function f in red and the last secant line in bold blue. In the graph, the x intercept of the secant line seems to be a good approximation of the root of f.
Below, the secant method is implemented in the Python programming language.
It is then applied to find a root of the function with initial points
x0=10
x1=30
def f_example(x): return x ** 2 - 612
root = secant_method(f_example, 10, 30, 5)
print(f"Root: ") # Root: 24.738633748750722
It is very important to have a good stopping criterion above, otherwise, due to limited numerical precision of floating point numbers, the algorithm can return inaccurate results if running for too many iterations. For example, the loop above can stop when one of these is reached first: abs(x0 - x1) < tol, or abs(x0/x1-1) < tol, or abs(f(x1)) < tol. [3]