Simulating physical systems

As a brief introduction to simulating physical systems, we will show you how to simulate Brownian motion in R. In physics, Brownian motion is defined as the random movement of particles suspended in liquid or gas caused by the collision of these particles in its surrounding medium. As a result, Brownian motion can be seen as a stochastic process continuous in time. We can simulate this process by successively adding random variables from a normal distribution, where the total number of normal random variables to be simulated represents the total number of discrete time intervals. For example, let's plot Brownian motion in one dimension using 10,000 discrete time intervals as follows:

> motion <- rnorm(10000, 0, 1)
> motion <- cumsum(motion)

> plot(motion, type="l", main="Brownian Motion in 1-Dimension", xlab="time", ylab="displacement")

The result is shown in the following plot:

Simulating physical systems

Alternatively, we could plot simple Brownian motion in two dimensions by simulating the distance for each coordinate separately, as follows:

> x.dist <- rnorm(10000, 0, 1)
> y.dist <- rnorm(10000, 0, 1)
> x.dist <- cumsum(x.dist)
> y.dist <- cumsum(y.dist)

> plot(x.dist, y.dist, type="l", main="Brownian Motion in 2-Dimensions", xlab="time", ylab="displacement")

The result is shown in the following plot:

Simulating physical systems

These are just two simple examples, but it does show you how simulating random variables from well-characterized distributions can be used to model physical systems.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.73.175