halley: Halley's Root Finding Mathod

Description Usage Arguments Details Value References See Also Examples

View source: R/newton.R

Description

Finding roots of univariate functions using the Halley method.

Usage

1
halley(fun, x0, maxiter = 500, tol = 1e-08, ...)

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)

...

additional arguments to be passed to the function.

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.

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

References

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

See Also

newtonRaphson

Examples

1
2
3
4
5
6
7
8
halley(sin, 3.0)        # 3.14159265358979 in 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

Example output

$root
[1] 3.141593

$f.root
[1] 1.224647e-16

$iter
[1] 3

$estim.prec
[1] 1.841549e-11

$root
[1] 0.5671433

$f.root
[1] 0

$iter
[1] 4

$estim.prec
[1] 0

$root
[1] 0.9061798

$f.root
[1] -4.440892e-16

$iter
[1] 4

$estim.prec
[1] 4.551914e-15

pracma documentation built on Dec. 11, 2021, 9:57 a.m.