Iteratng a Map

iterate <- function(n, f, x0, ...)
{
    x <- rep(NA, n)
    x[1] <- x0

    for (i in 1:(n-1)) {
        x[i+1] <- f(x[i], ...)
    }

    x
}

Linear Map

f <- function(x, alpha)
{
    alpha * x
}

alpha = +0.7

plot(iterate(30, f, x0=0.1, alpha=0.7), type="b", col=2)

alpha = -0.7

plot(iterate(30, f, x0=0.1, alpha=-0.7), type="b", col=2)

alpha = +1.7

plot(iterate(30, f, x0=0.1, alpha=1.7), type="b", col=2)

alpha = -1.7

plot(iterate(30, f, x0=0.1, alpha=-1.7), type="b", col=2)

Quadratic Map

f <- function(x, r)
{
    (1 + r) * x - r * x^2
}

Fixed Points

x <- seq(-0.5, 1.5, length.out=100)
plot(x, f(x, r=1.2), type="l", col=2)
lines(x, x, col=1, lty=2)

Fixed Point at 0

plot(iterate(10, f, x0=0.01, r=1.2), type="b", col=2)

Fixed Point at 1

plot(iterate(10, f, x0=1.01, r=1.2), type="b", col=2)

for (r in c(1.775, 2.0, 2.2, 2.525, 2.55, 2.7, 2.838)) {
    x <- iterate(130, f, x0=0.1, r=r)
    plot(x[101:130], type="b", col=2, main=paste("r =", r), xlab="", ylab="")
}