Skip to content

Instantly share code, notes, and snippets.

@hrbrmstr
Last active December 23, 2015 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrbrmstr/6625261 to your computer and use it in GitHub Desktop.
Save hrbrmstr/6625261 to your computer and use it in GitHub Desktop.
Random Walk The Plancks Constant! #RRRRRRRRRRRRRRRRRRRR
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
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