bisection_method: Bisection method

Description Usage Arguments Details Value Examples

View source: R/bisection_method.R

Description

The bisection method is an iterative root-finding method with linear convergence that does not use derivatives.

Usage

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

Arguments

f

Univariate function to find root of

x0

A point

x1

A point larger than x0

tol

Tolerance for convergence.

Details

The bisection method finds the root of a univariate function f given two initial guesses x_0 and x_1 where x_0 < x_1 and sign(f(x_0)) = -sign(f(x_1)) by sequentially bisecting the interval (x_2 = (x_0 + x_1) / 2).

Convergence is guaranteed as long as f is continuous in the interval [x_0, x_1] and f(x_0) and f(x_1) have opposite signs

The algorithm terminates when:

Value

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

Examples

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

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