Learn R Programming

pracma (version 1.8.8)

halley: Halley's Root Finding Mathod

Description

Finding roots of univariate functions using the Halley method.

Usage

halley(fun, x0,
        maxiter = 100, tol = .Machine$double.eps^0.5)

Arguments

fun
function whose root is to be found.
x0
starting value for the iteration.
maxiter
maximum number of iterations.
tol
absolute tolerance; default eps^(1/2)

Value

  • Return a list with components root, f.root, the function value at the found root, iter, the number of iterations done, and the estimated precision estim.prec

Details

Well known root finding algorithms for real, univariate, continuous functions; the second derivative must be smooth, i.e. continuous. The first and second derivative are computed numerically.

References

http://mathworld.wolfram.com/HalleysMethod.html

See Also

newtonRaphson

Examples

Run this code
halley(sin, 3.0)        # 3.14159265358979 in the 3 iterations
halley(function(x) x*exp(x) - 1, 1.0)
                        # 0.567143290409784 Gauss' omega constant

# Legendre polynomial of degree 5
lp5 <- c(63, 0, -70, 0, 15, 0)/8
f <- function(x) polyval(lp5, x)
halley(f, 1.0)          # 0.906179845938664

Run the code above in your browser using DataLab