newtons_method: Newtons's method

Description Usage Arguments Details Value Examples

View source: R/newtons_method.R

Description

Newtons's method is an iterative root-finding method with quadratic convergence that requires the first derivative.

Usage

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

Arguments

f

Univariate function to find root of

fp

First derivative of f

x0

A point close to the root of f

tol

Tolerance for convergence.

Details

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

x_{n + 1} = x_n - \frac{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
newtons_method(cos,
               function(x) -sin(x),
               0.5)
newtons_method(function(x) x ^ 3 - x - 2,
               function(x) 3 * x ^ 2 - 1,
               1)

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