Monte Carlo Simulations

In this lecture, we are going to analyze how drawing random states can help us figure out the properties of a system. In particular we will be looking at an approximation for $\pi$ through the darts experiment. In other words, the darts experiment, where you "hit" a point in a 2D space and find out whether the dart is inside a circle or outside it, is, in essence, an approximation to the area enclosed by the circle.

Dart problem

Let's first look at generating a large number of coordinate pairs such that $(x,y)\in [-1, 1]$. The x and y coordinates are drawn uniformly. Each value between -1 and 1 is equally likely. By figuring out the number of points which lie inside the circle against the total number of samples drawn, we obtain an estimate of $\pi$ as shown below. Essentially it is $4 \pi = \frac{N_t}{N}$ where $N_t$ represents the number of samples which lie inside the circle and $N$ represents the total number of samples.

The above figure demonstrates how the absolute eror in the estimate of $\pi$ converges as the number of samples drawn increases. We observe that $|\pi - \pi_e|\sim N^{-1/2}$.

Buffon's needle experiment

Next, we consider Buffon's needle experiment. In this experiment, there are parallel lines which are spaced at a distance $a$. We then toss a needle of length $b$ on the floor. We are interested in the probability that the needle intersects the line. Interestingly, this experiment also yields an expression for $\pi$ indirectly. Quite naturally, the outcome of this experiment also depends on the relative aspect ratio, i.e. $b/a$. The snippet below shows how we can use uniformly generated numbers, first for the angle of orientation of the needle with respect to the parallel lines, and the second, a compound expression involving the aspect ratio. The check for the intersection of the needle with the parallel line is performed and the number of such samples satifying the condition is compared to the total number of trials performed.

The above expression also provides for an estimate of $\pi$, albeit through a slightly more non-intuitive problem.