Other sites

Root finding

Numerical root finding methods use iteration, producing a sequence of numbers that hopefully converge towards a limits which is a root. In this post, only focus four basic algorithm on root finding, and covers bisection method, fixed point method, Newton-Raphson method, and secant method.

Root finding can be reduced to the problem of finding fixed points of the function g(x) = c*f(x) +x, where c is a non-zero constant. It is clearly that f(a) = 0 if and only if g(a) = a. This is the so called fixed point algorithm.

fixedpoint <-function(fun, x0, tol=1e-07, niter=500){## fixed-point algorithm to find x such that fun(x) == x## assume that fun is a function of a single variable## x0 is the initial guess at the fixed point
xold <- x0
xnew <- fun(xold)for(i in1:niter){
xold <- xnew
xnew <- fun(xold)if(abs((xnew-xold))< tol )return(xnew)}stop("exceeded allowed number of iterations")}

The secant method does not require the computation of a derivative, it only requires that the function f is continuous. The secant method is based on a linear approximation to the function f. The convergence properties of the secant method are similar to those of the Newton-Raphson method.