Iterate: Iterate a function on an initial condition

Description Usage Arguments Details Value Examples

View source: R/iterate.R

Description

Iterates a function a specified number of times on an initial condition.

Usage

1
Iterate(f = NULL, A = NULL, x0 = 0, n = 10, fargs = list())

Arguments

f

a function of one or more state variables which returns a vector containing those same state variables. Parameters to f(), if any, should be named and at the end of the argument list. State variables should not have default values.

A

As an alternative to f you can give a square matrix and iteration will be done on the system xn+1 = A xn. In lieu of a square matrix you can also give a vector to be rendered into a square matrix rowwise.

x0

a vector with the numerical initial condition. There should be 1 component in x0 for each of the state variables in f().

n

an integer specifying the number of iterations

fargs

list containing values for numerical parameters to the function f()

Details

The function f can take one or more arguments. The first of these should represent the state of the dynamical system, e.g. x, or x and y, etc. At the end of the argument list to f can come named parameters. The length of the initial condition x0 must match the number of state arguments. Numerical values for parameters (if any) must be provided in the ... slot.

Value

A data frame with a column .i listing the iteration number and columns for each component of the initial condition. There will be n+1 rows, the first for the initial condition and the remaining for the n iterations.

Examples

1
2
3
4
Iterate(function(x, mu=3.5) mu*x*(1-x), .232, n=10, list(mu=4)) # chaos
Iterate(function(x, y) c(x+y, x-y), c(1,1), n=10)
Iterate(function(x, y) c(x+y, x), c(1,0), n=10) # fibonacci
Iterate(A = [1 1 1 0], c(1,0), n=5) # fibonacci described by a matrix

dtkaplan/mosaicUSAFA documentation built on Aug. 21, 2021, 10:37 p.m.