Secant method
640746
224242081
2008-07-07T23:25:05Z
Plasticup
2666389
minor tidying (please [[User_Talk:Plasticup|tell me]] about errors!) using [[Project:AutoWikiBrowser|AWB]]
In [[numerical analysis]], the '''secant method''' is a [[root-finding algorithm]] that uses a succession of [[root (mathematics)|root]]s of [[secant line]]s to better approximate a [[root (mathematics)|root]] of a [[Function (mathematics)|function]] ''f''.
==The method==
[[Image:Secant method.svg|right|thumb|The first two iterations of the secant method. The red curve shows the function ''f'' and the blue lines are the secants.]]
The secant method is defined by the [[recurrence relation]]
:<math>x_{n+1} = x_n - \frac{x_n-x_{n-1}}{f(x_n)-f(x_{n-1})} f(x_n). </math>
As can be seen from the recurrence relation, the secant method requires two initial values, ''x''<sub>0</sub> and ''x''<sub>1</sub>, which should ideally be chosen to lie close to the root.
==Derivation of the method==
Given ''x''<sub>''n''−1</sub> and ''x''<sub>''n''</sub>, we construct the line through the points (''x''<sub>''n''−1</sub>, ''f''(''x''<sub>''n''−1</sub>)) and (''x''<sub>''n''</sub>, ''f''(''x''<sub>''n''</sub>)), as demonstrated in the picture on the right. Note that this line is a [[secant]] or chord of the graph of the function ''f''. In [[slope|point-slope form]], it can be defined as
:<math> y - f(x_n) = \frac{f(x_n)-f(x_{n-1})}{x_n-x_{n-1}} (x-x_n). </math>
We now choose ''x''<sub>''n''+1</sub> to be the root of this line, so ''x''<sub>''n''+1</sub> is chosen such that
:<math> f(x_n) + \frac{f(x_n)-f(x_{n-1})}{x_n-x_{n-1}} (x_{n+1}-x_n) = 0. </math>
Solving this equation gives the recurrence relation for the secant method.
==Convergence==
The iterates ''x''<sub>''n''</sub> of the secant method converge to a root of ''f'', if the initial values ''x''<sub>0</sub> and ''x''<sub>1</sub> are sufficiently close to the root. The [[order of convergence]] is α, where
:<math> \alpha = \frac{1+\sqrt{5}}{2} \approx 1.618 </math>
is the [[golden ratio]]. In particular, the convergence is superlinear.
This result only holds under some technical conditions, namely that ''f'' be twice continuously differentiable and the root in question be simple (i.e., that it not be a repeated root).
If the initial values are not close to the root, then there is no guarantee that the secant method converges.
==Comparison with other root-finding methods==
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]] uses the same formula as the secant method. However, it does not apply the formula on ''x''<sub>''n''−1</sub> and ''x''<sub>''n''</sub>, like the secant method, but on ''x''<sub>''n''</sub> and on the last iterate ''x''<sub>''k''</sub> such that ''f''(''x''<sub>''k''</sub>) and ''f''(''x''<sub>''n''</sub>) have a different sign. This means that the false position method always converges.
The recurrence formula of the secant method can be derived from the formula for [[Newton's method]]
:<math> x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} </math>
by using the [[finite difference]] approximation
:<math> f'(x_n) \approx \frac{f(x_n)-f(x_{n-1})}{x_n-x_{n-1}}. </math>
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'' and its derivative at every step, while the secant method only requires the evaluation of ''f''. Therefore, the secant method may well be faster in practice. For instance, if we assume that evaluating ''f'' takes as much time as evaluating its derivative and we neglect all other costs, we can do two steps of the secant method (decreasing the logarithm of the error by a factor α² ≈ 2.6) for the same cost as one step of Newton's method (decreasing the logarithm of the error by a factor 2), so the secant method is faster.
==Generalizations==
[[Broyden's method]] is a generalization of the secant method to more than one dimension.
==Example code==
The following [[C (programming language)|C]] code was written for clarity instead of efficiency. It was designed to solve the same problem as solved by the [[Newton's method]] and [[false position method]] code: to find the positive number ''x'' where cos(''x'') = ''x''<sup>3</sup>. This problem is transformed into a root-finding problem of the form ''f''(''x'') = cos(''x'') − ''x''<sup>3</sup> = 0.
In the code below, the secant method continues until one of two conditions occur:
#<math> |x_{n+1} - x_n| < \epsilon </math>
#<math> n > m </math>
for some given ''m'' and ''ε''.
#'''include''' <stdio.h>
#'''include''' <math.h>
'''double''' f('''double''' x)
{
'''return''' cos(x) - x*x*x;
}
'''double''' SecantMethod('''double''' xn_1, '''double''' xn, '''double''' e, '''int''' m)
{
'''int''' n;
'''double''' d;
'''for''' (n = 1; n <= m; n++)
{
d = (xn - xn_1) / (f(xn) - f(xn_1)) * f(xn);
'''if''' (fabs(d) < e)
'''return''' xn;
xn_1 = xn;
xn = xn - d;
}
'''return''' xn;
}
'''int''' main('''void''')
{
printf("%0.15f\n", SecantMethod(0, 1, 5E-11, 100));
'''return''' 0;
}
After running this code, the final answer is approximately 0.865474033101614. The initial, intermediate, and final approximations are listed below, correct digits are underlined.
:<math> x_0 = 0 \,\!</math>
:<math> x_1 = 1 \,\!</math>
:<math> x_2 = 0.685073357326045 \,\!</math>
:<math> x_3 = 0.\underline{8}41355125665652 \,\!</math>
:<math> x_4 = 0.\underline{8}70353470875526 \,\!</math>
:<math> x_5 = 0.\underline{865}358300319342 \,\!</math>
:<math> x_6 = 0.\underline{86547}3486654304 \,\!</math>
:<math> x_7 = 0.\underline{8654740331}63012 \,\!</math>
:<math> x_8 = 0.\underline{865474033101614} \,\!</math>
The following graph shows the function ''f'' in red and the last secant line in blue. In the graph, the ''x''-intercept of the secant line seems to be a good approximation of the root of ''f''.
[[Image:Secant method example code result.svg|center]]
==External links==
* [http://math.fullerton.edu/mathews/a2001/Animations/RootFinding/SecantMethod/SecantMethod.html Animations for the secant method]
* [http://twt.mpei.ac.ru/MAS/Worksheets/secant.mcd Secant method of zero (root) finding on Mathcad Application Server]
* [http://numericalmethods.eng.usf.edu/topics/secant_method.html Secant Method] Notes, PPT, Mathcad, Maple, Mathematica, Matlab at ''Holistic Numerical Methods Institute''
* {{MathWorld|urlname=SecantMethod|title=Secant Method}}
*[http://math.fullerton.edu/mathews/n2003/SecantMethodMod.html Module for Secant Method by John H. Mathews]
[[Category:Root-finding algorithms]]
[[de:Sekantenverfahren]]
[[fr:Méthode de la sécante]]
[[it:Metodo delle corde]]
[[he:שיטת המיתר]]
[[nl:Secant-methode]]
[[pl:Metoda siecznych]]
[[ru:Метод секущих]]
[[sr:Метода сечице]]
[[fi:Sekanttimenetelmä]]