Description Usage Arguments Value Examples
fp
will iteratively evaluate a fixed-point function.
It only supplies the user with some generally usefull and
standardised output.
1 |
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 |
... |
additional arguments passed to |
Returns a list including:
x numeric. The
solution for x or the value at the last iteration if the
maximum number of iterations are reached or fun
results in an error.
iterations numeric. The iteration where the algorithm stopped.
returnStatus numeric. Code indicating the return status:
0 reached tolerance criterion
1 reached max number of iterations
2 exit with error - last valid x is returned
errorMessage if fun
resulted in an
error, the error message
errorCall if fun
resulted in an error, the call
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.