secant_method: Secant method

Description Usage Arguments Details Value Examples

View source: R/secant_method.R

Description

The secant method is an iterative root-finding method with order of convergence phi (1.618...) that does not use derivatives.

Usage

1
secant_method(f, x0, x1, tol = 1e-08)

Arguments

f

Univariate function to find root of

x0

A point close to the root of f

x1

A point close to the root of f not equal to x0

tol

Tolerance for convergence.

Details

The secant method finds the root of a univariate function f given two initial guesses x_0 and x_1 by the iteration:

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

.

The algorithm terminates when:

Value

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

Examples

1
2
secant_method(cos, 0, 1)
secant_method(function(x) x ^ 3 - x - 2, 1, 2)

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