Mario Becerra

Pi estimation using simulation

There are many ways to estimate the value of \(\pi\), some more efficient than others. One of them is using Monte Carlo simulation. The idea is that if you have a circle of radius 1, it will have an area of \(\pi\). You can fit a circle within a square of area 4, such that they both have a centroid in the origin, like shown in the following image.

Then, if one simulates \(N\) points in the square, counts how many were inside the circle (\(N_{in}\)) and computes \(\frac{N_{in}}{N}\), one gets a number close to \(\frac{\pi}{4}\). And the bigger \(N\) gets, the closer one is to the real value of \(\pi\). So, to estimate \(\pi\), one computes \(4\frac{N_{in}}{N}\). An example of the simulated points can be seen in the following figure (done in R).

tibble(x = runif(10000, -1, 1),
               y = runif(10000, -1, 1)) %>% 
  mutate(inside = x^2 + y^2 < 1) %>% 
  ggplot() +
  geom_point(aes(x, y, color = inside), size = 0.5) +
  coord_equal() +