In numerical analysis, Newton Raphson Method is a method for finding successively better approximations to the roots (or zeroes) of a real-valued function.

As mentioned in Wikipedia, the idea of the method is as follows: one starts with an initial guess which is reasonably close to the true root, then the function is approximated by its tangent line (which can be computed using the tools of calculus), and one computes the x-intercept of this tangent line (which is easily done with elementary algebra). This x-intercept will typically be a better approximation to the function’s root than the original guess, and the method can be iterated.

The function newton.method() in the animation package can give you a demonstration of the Newton-Raphson Method. Let’s set the function , the starting point is 7.15 and the interval is .

library(animation)
ani.options(nmax = 100, interval = 1)
par(mar = c(3, 3, 1, 1.5), mgp = c(1.5, 0.5, 0), pch = 19)
newton.method(function(x) 5 * x^3 - 7 * x^2 - 40 * x + 100, init = 7.15, 
  rg = c(-6.2, 7.1))

The algorithm might not converge – it depends on the starting value. See the examples below.

## does not converge!
par(mar = c(3, 3, 1, 1.5), mgp = c(1.5, 0.5, 0), pch = 19)
xx = newton.method(function(x) atan(x), rg = c(-5, 5), init = 1.5)
xx$root  # Inf
## [1] Inf


Published

30 April 2013

Tags