Skip to content

Instantly share code, notes, and snippets.

@af12066
Created May 21, 2016 13:09
Show Gist options
  • Save af12066/caf8d85ca71fbfb5701e9de92c873990 to your computer and use it in GitHub Desktop.
Save af12066/caf8d85ca71fbfb5701e9de92c873990 to your computer and use it in GitHub Desktop.
Aの増加にともなうカオスのようすをみる.
library(gganimate) # https://github.com/dgrtwo/gganimate
n.seq <- 1:(num/20) #ステップ数
x.rep <- tail(n.seq, n = 1) #最大ステップ数
A.seq <- seq(0.1, 4.0, 0.05) #Aを0.1から0.05刻みに増加させたときのようすを見る.
logistic <- function(A, x, n){
npforeach(i = 1:n)({
x <- A * x * (1 - x)
}) -> y
return(y) #ステップごとのxの値を出力させた.
}
npforeach(a = A.seq, .c = rbind)({
x <- logistic(a, 0.01, x.rep)
data.frame(A=a, x=x, n=n.seq)
}) -> y2
g2 <- ggplot(y2, aes(n, x, frame = A)) + geom_line(size = 0.3)
gg_animate(g2, interval = .5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment