Learn R Programming

animation (version 0.2-0)

brownian.motion: Demonstration of Brownian motion on the 2D plane

Description

Demonstrate Brownian motion (random walk) in a 2D scatterplot.

Usage

brownian.motion(n = 10, main = "Demonstration of Brownian Motion", 
    xlim = c(-20, 20), ylim = c(-20, 20), pch = 21, cex = 5, 
    col = "red", bg = "yellow", control = ani.control(nmax = 100, 
    interval = 0.05), ...)

Arguments

n
Number of points in the scatterplot
main, xlim, ylim, pch, cex, col, bg
Arguments passed to plot.default to control the apperance of the scatterplot (title, points, etc), see points for deta
control
control parameters for the animation; see ani.control
...
other arguments passed to ani.control

Value

  • None (invisible `NULL').

Details

Brownian motion, or random walk, can be regarded as the trace of some cumulative normal random numbers: the location of the next step is just ``current location + random Gaussian numbers'', i.e., $$x_{k + 1} = x_{k} + rnorm(1);\;\; y_{k + 1} = y_{k} + rnorm(1)$$ where (x, y) stands for the location of a point.

See Also

ani.start, ani.stop

Examples

Run this code
# show an animation in (Windows/X Window...) a graphics device 
# unless you have opened an invisible device like png(), pdf(), ... 
brownian.motion(n = 15, nmax = 150) 

# create HTML animation page
ani.start()
brownian.motion(n = 15, nmax = 100, saveANI = TRUE, width = 500,
    height = 500) 
ani.stop()

Run the code above in your browser using DataLab