Brownian action : a still motion picture
Brownian motion is used to describe processes as varied as the movement of dust particles in a room, stock market patterns and the distribution of the Kolmogorov-Smirnov statistic. It is described as random with seemingly no apparent order that you can make out to predict the next position of the particle in time. Non-deterministic/ stochastic processes is what you call them. To generate Brownian motion on a computer is easy however and this post will show you how to go about it in R.
install.packages("rgl") # we need this for 3-D visualization
if this install fails on linux you need to install "libglu1-mesa-dev" using apt-get or yum or whatever package manager that you prefer.
So a Brownian walk is the averaged out motion of a particle which is equally likely to go in one direction as the other at stochastic intervals such that the mean motion is nearly zero.
library(rgl)
rxyz<-matrix(runif(3*100000,-1,1),,3) # fill 3 columns of a matrix with randomly uniform numbers
crxyz<-apply(rxyz,2,cumsum) # integrate the motion over time with cumulative sum
plot3d(crxyz,type="l",col="red") # plot the integration in 3-D
So here what we do is generate x,y,z trajectory for a particle for 100000 instances. Now the co-ordinates of the trajectory are completely random uniformly distributed between -1 and 1 such that the mean value of the motion is close to zero, however because of small differences in the randomly generated values, there is an average motion that is still random in the x,y and z axes.
This is a 2-D plot of the motion in the x,y axis generated using
plot(crxyz[,1],crxyz[,2],type="l",col="red")
The 3-D plot allows you to visualize and rotate the motion in 3-D and observe the fine structure of the random walk by zooming in and out.
That is it, now enjoy your drunken walks knowing that you can still integrate when you are high.
No comments:
Post a Comment