Last active
December 23, 2015 10:59
-
-
Save hrbrmstr/6625261 to your computer and use it in GitHub Desktop.
Random Walk The Plancks Constant! #RRRRRRRRRRRRRRRRRRRR
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
set.seed(200109) # founding of The Pirate Bay | |
walk<-function(n) { | |
m <- matrix(6.62606896e-34, ncol = 2, nrow = n) | |
i <- cbind(seq(n), sample(c(1, 2), n, TRUE)) | |
m[i] <- sample(c(-1, 1), n, TRUE) | |
m[,1] <- cumsum(m[, 1]) | |
m[,2] <- cumsum(m[, 2]) | |
m | |
} | |
m <- walk(1000) | |
plot(0, type="n",xlab="x", ylab="y", main="Random Walk The Plancks Constant", xlim=range(m[,1]), ylim=range(m[,2])) | |
segments(head(m[, 1], -1), head(m[, 2], -1), tail(m[, 1], -1), tail(m[,2], -1), col ="blue") | |
# see plot here: http://flic.kr/p/fXMcrm |
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
set.seed(200109) # founding of The Pirate Bay | |
walk<-function(n) { | |
m <- matrix(6.62606896e-34, ncol = 2, nrow = n) | |
i <- cbind(seq(n), sample(c(1, 2), n, TRUE)) | |
m[i] <- sample(c(-1, 1), n, TRUE) | |
m[,1] <- cumsum(m[, 1]) | |
m[,2] <- cumsum(m[, 2]) | |
m | |
} | |
m <- walk(1000) | |
gg <- ggplot(data.frame(m), aes(x=X1, y=X2)) | |
gg <- gg + geom_path() | |
gg <- gg + coord_equal() | |
gg <- gg + labs(x="", y="", title="Random Walk The Plancks Constant") | |
gg <- gg + theme_bw() | |
gg <- gg + theme(panel.grid=element_blank()) | |
gg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment