Created
July 21, 2014 15:13
-
-
Save joe11051105/4d2222fab36117685ed9 to your computer and use it in GitHub Desktop.
20140721 R Group ans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(list = ls()) | |
iter = 10000 | |
p = runif(iter) | |
coord = matrix(c(0, 0), ncol = 1) | |
df = rbind(data.frame(), t(coord)) | |
for (i in 1:iter) { | |
indicator = runif(1, 0, 1) | |
if (indicator <= 0.05) { | |
m = matrix(c(0, 0, 0, 0.16), nrow = 2, ncol = 2) | |
const = matrix(c(0, 0), ncol = 1) | |
} else if (p[i] > 0.05 && p[i] <= 0.86) { | |
m = matrix(c(0.85, -0.04, 0.04, 0.85), nrow = 2, ncol = 2) | |
const = matrix(c(0, 1.6), ncol = 1) | |
} else if (p[i] > 0.86 && p[i] <= 0.93) { | |
m = matrix(c(0.2, 0.23, -0.26, 0.22), nrow = 2, ncol = 2) | |
const = matrix(c(0, 1.6), ncol = 1) | |
} else { | |
m = matrix(c(-0.15, 0.26, 0.28, 0.24), nrow = 2, ncol = 2) | |
const = matrix(c(0, 0.44), ncol = 1) | |
} | |
coord = m %*% coord + const | |
df = rbind(df, t(coord)) | |
} | |
plot(x = df[, 2], y = df[, 1], plt = c(0, 10, -5, 5), cex = 0.1, asp = 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment