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. However, the secant method predates Newton's method by over 3000 years.[1]
For finding a zero of a function, the secant method is defined by 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) |
.
As can be seen from this formula, two initial values and are required. Ideally, they 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
\varphi
\varphi=
1+\sqrt{5 | |
This result only holds under some technical conditions, namely that
f
If the initial values are not close enough to the root, then there is no guarantee that the secant method converges. There is no general definition of "close enough", but the criterion has to do with how "wiggly" the function is on the interval
[x0,x1]
f
f'=0
The secant method does not require that the root remain bracketed, 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
f'(xn-1) ≈
f(xn-1)-f(xn-2) | |
xn-1-xn-2 |
≈ {
| ||||||||||
)-f(x |
n-1-{
\epsilon | |
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 φ ≈ 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. [2]