Roots of Nonlinear Functions

Secant Method

Secant Method

The secant method is an iterative procedure to estimate a root of an equation f(x) = 0 where the user gives two initial estimates and a tolerance. One of the two initial estimates is regarded as being older than the other, the procedure then calculates a new estimate and discards the oldest estimate until the distance between the two estimates is less than the preassigned tolerance. If xi-1 and xi are the two estimates with xi-1 being older than xi, the new estimate xi+1 is that point on the x-axis which is the intersection of the x-axis and the line joining the points ( xi-1, f(xi-1) ) and ( xi, f(xi) ) on the curve y = f(x). The subsequent estimate then uses the points ( xi, f(xi) ) and ( xi+1, f(xi+1) ) to estimate xi+1.
It is best to avoid using the secant method if there are local extrema near the root. The convergence of the secant method depends on the initial estimates. It is generally better if the two initial conditions are close so that the secant is approximately equal to the tangent.

Function List

  • double Secant_Method( double (*f)(double), double a, double b, double tolerance, int max_iteration_count, int *err)

    Find a root of f(x) in near a and b. The procedure terminates when the absolute difference of the return value and the actual root is less than tolerance, where tolerance is a user specified number specifying the desired accuracy of the result. The input argument max_iteration_count allows the user to control the maximum number of iterations to attempt. The method returns an err of 0 if the iteration was successful, -1 if the number of iterations exceed the maximum allowable number of iterations as specified by the user, and -2 if an attempt was made to divide by zero, which is indicative of a local minimum or a local maximum. Even if the an err return of 0 occurs, it is possible that the result is erroneous, especially if there is a local minimum or local maximum near the root. For this reason, if it is not known whether there is a local extremum in a small neighborhood of the root, the result should be checked for its validity.

C Source Code

  • The file, secant_method.c, contains the version of Secant_Method( ) written in C.