iterate | R Documentation |
Iteration function
iterate(x, f, times = 100, tol = NA, ...)
x |
the initial state vector. If x has a name attribute, the names will be used to label the output matrix. |
f |
a user-supplied function that computes the values of the next time. |
times |
the iteration times. |
tol |
the tolerance for stopping calculation. If the canberra distance of the last two state vectors is less than tol the calculation will stop. |
... |
optional arguments passed to the f function. |
A matrix consisting of state vectors.
x <- c(1, 2)
f <- function(x, a) prop.table(c(sum(x), a * prod(x)^(1 / 2)))
iterate(x, f, 100, a = 3)
iterate(x, f, 100, tol = 1e-5, a = 3)
#### Heron's method for finding square roots
x <- 1
f <- function(x, n) (x + n / x) / 2
iterate(x, f, 10, n = 5)
#### Find a root of the equation x^3-x-1==0.
x <- 1.5
f <- function(x) (x + 1)^(1 / 3)
iterate(x, f, 10)
####
x <- c(1, 2, 3)
f <- function(x) {
n <- length(x)
sigma <- seq(-1, 1, length.out = n)
result <- rep(NA, n)
for (k in 1:n) result[k] <- CES(sigma[k], 1, rep(1 / n, n), x, rep(1 / n, n))
prop.table(result)
}
iterate(x, f, 100)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.