[This article was first published on stotastic » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
In 1827, the botanist Robert Brown was studying pollen particles as they floated in water. When viewed through a microscope, he observed that the particles seemed to move around as if the were alive. Although he couldn’t have known at the time, the seemingly random motion was caused by the collision of water molecules against the pollen particle. Later on, the random motion he observed would be given the name ‘Brownian Motion’.
Simulating Brownian Motion
We can model what Brown may have seen by simulating a two dimensional Brownian Motion. Executing the following code in R will produce a chart as if we had recorded the location of the pollen particle every minute (or some other arbitrary time interval) and connected the points in sequence.
n <- 100 y <- rep(0,n) x <- rep(0,n) for(i in 2:n){ y[i] <- y[i-1] + rnorm(1,0,1) x[i] <- x[i-1] + rnorm(1,0,1) } plot(x,y, type="l", col="blue", ylim=c(-10,10), xlim=c(-10,10))
To leave a comment for the author, please follow the link and comment on their blog: stotastic » R.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.