bisection: A function of the bisection algorithm.

Description Usage Arguments Details Value References See Also Examples

View source: R/bisection.R

Description

Applies the bisection algorithm to find x such that ftn(x) == x.

Usage

1
bisection(ftn, x.l, x.r, tol = 1e-09)

Arguments

ftn

the function.

x.l

is the lower starting point.

x.r

is the upper starting point.

tol

distance of successive iterations at which algorithm terminates.

Details

We assume that ftn is a function of a single variable.

Value

Returns the value of x at which ftn(x) == x. If the function fails to converge within max.iter iterations, returns NULL.

References

Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientific Programming and Simulation, Using R. Chapman And Hall/CRC.

See Also

newtonraphson, fixedpoint

Examples

1
2
ftn5 <- function(x) return(log(x)-exp(-x))
bisection(ftn5, 1, 2, tol = 1e-6)

Example output

Loading required package: MASS
Loading required package: lattice
at iteration 1 the root lies between 1 and 1.5 
at iteration 2 the root lies between 1.25 and 1.5 
at iteration 3 the root lies between 1.25 and 1.375 
at iteration 4 the root lies between 1.25 and 1.3125 
at iteration 5 the root lies between 1.28125 and 1.3125 
at iteration 6 the root lies between 1.296875 and 1.3125 
at iteration 7 the root lies between 1.304688 and 1.3125 
at iteration 8 the root lies between 1.308594 and 1.3125 
at iteration 9 the root lies between 1.308594 and 1.310547 
at iteration 10 the root lies between 1.30957 and 1.310547 
at iteration 11 the root lies between 1.30957 and 1.310059 
at iteration 12 the root lies between 1.30957 and 1.309814 
at iteration 13 the root lies between 1.309692 and 1.309814 
at iteration 14 the root lies between 1.309753 and 1.309814 
at iteration 15 the root lies between 1.309784 and 1.309814 
at iteration 16 the root lies between 1.309799 and 1.309814 
at iteration 17 the root lies between 1.309799 and 1.309807 
at iteration 18 the root lies between 1.309799 and 1.309803 
at iteration 19 the root lies between 1.309799 and 1.309801 
at iteration 20 the root lies between 1.309799 and 1.3098 
[1] 1.3098

spuRs documentation built on May 2, 2019, 12:44 p.m.

Related to bisection in spuRs...