Estimating the area by throwing random points

Tivadar Danka small portrait Tivadar Danka
The Monte Carlo method

Understanding math will make you a better engineer.

So, I am writing the best and most comprehensive book about it.

One of the coolest ideas in mathematics is the estimation of a shape's area by throwing random points at it.

Don't believe this works? Check out the animation below, where I show the method on the unit circle. (Whose area equals to π\pi.)

Here is what's behind the magic.

Let's make this method precise! The first step is to enclose our shape SS in a square. You can imagine this as a rectangular dartboard.

A random shape

Now, we select random points from the board and count how many hit the target.

Again, you can imagine this as closing your eyes, doing a 360° spin, then launching a dart. (Suppose that you always hit the board. Yes, I know. But in math, reality doesn't limit imagination.)

The Monte Carlo method in action

The proportion of points inside the shape will approximate the ratio of areas.

Why on earth does this work?

The Monte Carlo method in action

Let's start with the definition of "random". There are many ways of selecting a random point from the board.

We use the uniform distribution. This means that the probability of the point hitting our shape is the ratio of the areas.

The uniform distribution

We don't care about the exact position of a random point, just whether it hits our shape or not.

Thus, we describe each "dart" by a 010-1 value. 00 if it is a miss, 11 if it is a hit.

Bernoulli random variables

In the language of probability, the ξ\xi-s are called Bernoulli random variables. Each random point is independent of the others, and their distribution is identical.

Thus, the Law of Large Numbers holds: their average (almost surely) converges to the expected value. (Our Bernoulli variables are identically distributed, so their expected values are equal.)

The Law of Large Numbers

On a second look, the average can be written as the total number of hits divided by the total number of points. (Recall that the value of each variable is 00 if it is a miss and 11 if it is a hit.)

Frequency of hits

On the other hand, the expected value is the probability of a hit. That is, the area of our shape divided by the area of the rectangular board!

Expected value of the hit

Combining these two observations, we get that the frequency of hits converges to the ratio of the areas.

Thus, we can approximate the area by simply counting the number of hits.

This is one of the coolest ideas in mathematics.

The Monte Carlo method

The general method is called "Monte Carlo integration", and as the name suggests, it can be used to evaluate integrals of chunky functions. Even ones with lots of variables.

There are drawbacks, like the slow convergence, which has a rate of 1/n1/\sqrt{n}, where n is the number of points selected.

However, there is no denying it: estimating the area of an object by throwing random points is pretty awesome.

Having a deep understanding of math will make you a better engineer.

I want to help you with this, so I am writing a comprehensive book that takes you from high school math to the advanced stuff.
Join me on this journey and let's do this together!