halleys_method: Halley's method

Description Usage Arguments Details Value Examples

View source: R/halleys_method.R

Description

Halley's method is an iterative root-finding method with cubic convergence that requires the first and second derivative.

Usage

1
halleys_method(f, fp, fpp, x0, tol = 1e-08)

Arguments

f

Univariate function to find root of

fp

First derivative of f

fpp

Second derivative of f

x0

A point close to the root of f

tol

Tolerance for convergence.

Details

Halley's method finds the root of a univariate function f with first derivative f' and second derivative f'' given an initial guess x_0 by the iteration:

x_{n + 1} = x_n - \frac{2f(x_n)f'(x_n)}{2(f'(x_n))^2 - f(x_n)f''(x_n)}

.

The algorithm terminates when:

Value

A root of f near x0. If the algorithm does not converge, NA is returned.

Examples

1
2
3
4
5
6
7
8
halleys_method(cos,
               function(x) -sin(x),
               function(x) -cos(x),
               0.5)
halleys_method(function(x) x ^ 3 - x - 2,
               function(x) 3 * x ^ 2 - 1,
               function(x) 6 * x,
               1)

steventhornton/univariate documentation built on June 5, 2020, 2:37 p.m.