fixedpoint: A function of the fixed point algorithm.

Description Usage Arguments Details Value References See Also Examples

View source: R/fixedpoint.R

Description

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

Usage

1
fixedpoint(ftn, x0, tol = 1e-09, max.iter = 100)

Arguments

ftn

the function.

x0

is the initial guess at the fixed point.

tol

distance of successive iterations at which algorithm terminates.

max.iter

maximum number of iterations.

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, bisection

Examples

1
2
ftn1 <- function(x) return(exp(exp(-x)))
fixedpoint(ftn1, 2, tol = 1e-6)

Example output

Loading required package: MASS
Loading required package: lattice
At iteration 1 value of x is: 1.144921 
At iteration 2 value of x is: 1.374719 
At iteration 3 value of x is: 1.287768 
At iteration 4 value of x is: 1.317697 
At iteration 5 value of x is: 1.307022 
At iteration 6 value of x is: 1.310783 
At iteration 7 value of x is: 1.309452 
At iteration 8 value of x is: 1.309922 
At iteration 9 value of x is: 1.309756 
At iteration 10 value of x is: 1.309815 
At iteration 11 value of x is: 1.309794 
At iteration 12 value of x is: 1.309802 
At iteration 13 value of x is: 1.309799 
At iteration 14 value of x is: 1.3098 
Algorithm converged
[1] 1.3098

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

Related to fixedpoint in spuRs...