fp: Implementation of fixed-point algorithm

Description Usage Arguments Value Examples

View source: R/fp.R

Description

fp will iteratively evaluate a fixed-point function. It only supplies the user with some generally usefull and standardised output.

Usage

1
fp(fun, x0, opts = list(tol = 1e-06, maxiter = 100), ...)

Arguments

fun

the function returning the 'fixed-point' of x

x0

starting value for x. Will be coerced to numeric.

opts

list of options used in the algorithm. At this point only tol and maxiter are supported

...

additional arguments passed to fun

Value

Returns a list including:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
iterator <- function(x) {
force(x)
function(guess) {
 ret <- mean(c(guess, x/guess))
 if(ret == -Inf) stop("algorithm ended with -Inf!")
 ret
}
}

# Finding the square root of 2:
x2 <- fp(fun = iterator(2), x0 = 1)

print(x2)
summary(x2)

# Finding the square root of -1 - fun will result in an error:
x_1 <- fp(fun = iterator(-1), x0 = 1)

print(x_1)
summary(x_1)

wahani/fuTools documentation built on May 3, 2019, 7:38 p.m.