# NOT RUN {
# https://en.wikipedia.org/wiki/Collatz_conjecture
syracuse <- function(x) if (x %% 2) 3 * x + 1 else x / 2
iterate(
10,
syracuse,
stop_fun = function(n) n == 1,
accumulate = TRUE
)
# https://en.wikipedia.org/wiki/H%C3%A9non_map
henon_attractor <-
iterate(
c(-1, 0.1),
function(x) c(1 - 1.4 * x[1]^2 + x[2], 0.3 * x[1]),
stop_n = 5000,
accumulate = TRUE
)
plot(
sapply(henon_attractor, function(.) .[1]),
sapply(henon_attractor, function(.) .[2]),
pch = "."
)
# }
Run the code above in your browser using DataLab