06/08/2026

What is the Monte Carlo Simulation?

The Monte Carlo Simulation is a statistical technique that is used to predict outcomes based on estimates of probability and other input values that are assumed to have a certain distribution. The simulation works by repeatedly sampling the data and calculation outcomes based on the model. It is typically used to solve problems that are too complex for exact analytic solutions.

Main Idea

  • Generate a large number of random samples
  • Use the results to estimate the value of interest
  • The greater the samples, the more accurate the estimate

How it works?

We estimate \(\pi\) by randomly throwing darts in a unit square containing a circle.

Assuming the darts land uniformly at random, the probability a dart lands inside the circle equals the ratio of the areas:

\[P(\text{Dart inside circle}) = \frac{\text{Area of circle}}{\text{Area of square}} = \frac{\pi r^2}{(2r)^2} = \frac{\pi}{4}\] That means that if we throw \(n\) darts and \(k\) land in the circle, we estimate:

\[\hat{\pi} \approx 4 \times \frac{k}{n}\] The Law of Large Numbers guarantees \(\hat{\pi} \to \pi\) as \(n \to \infty\).

Dart Throwing Setup

We assume there is a unit circle inscribed in a \(2 \times 2\) square:

  • Randomly sample points \((x_i,\ y_i)\) where \(x_i, y_i \sim \text{Uniform}(-1,\ 1)\)

  • A point is inside the circle if:

\[x_i^2 + y_i^2 \leq 1\]

  • We count the number of points that fall inside and use:

\[\hat{\pi} = 4 \cdot \frac{\#\left\{(x_i,\ y_i)\ :\ x_i^2 + y_i^2 \leq 1\right\}}{n}\]

With \(n = 20{,}000\) random darts, we obtain \(\hat{\pi}\) = 3.146 compared to the true value \(\pi\) = 3.1416.

Scatter Plot Visualization

Convergence of Estimates

As we keep throwing more darts, they start to converge towards the true value of \(\pi\):

3D Graph

R Code

set.seed(100)
n=20000

x=runif(n,-1,1)
y=runif(n,-1,1)

circle=(x^2 + y^2)<=1

estimate_of_pi=round(4*sum(circle)/n, 4)

df=data.frame(
  x=x,
  y=y,
  circle=factor(circle, labels=c("Outside", "Inside"))
)

run_pi=4*cumsum(circle)/(1:n)
conv_df=data.frame(
  n_darts=1:n,
  estimate_of_pi=run_pi
)

Accuracy vs. Num of Darts

What this all means

We used a Monte Carlo Simulation to estimate values that would have otherwise been too difficult to calculate.

We “threw” \(n = 20{,}000\) random darts and estimated \(\hat{\pi}\) = 3.146

compared to the true value of \(\pi\) = 3.14159

The Graphs

  • Scatter Plot Visualization: the purple points were all the darts inside and teal were the ones outside
  • Convergence of Estimates Plot: as \(n\) grows, \(\hat{\pi}\) stabilizes to the true pi value
  • 3D Graph: shows us that inside vs outside is determined by the distance of the dart from the center.
  • Accuracy vs. Num of Darts Error Plot: the more darts we throw, the lower the error becomes before stabilizing