Monday, June 22, 2015

The Good Ol' Guess and Check Method, Hardcore Science Style

Do you remember when you learned what pi was for the very first time? I don't, but I do remember wondering how people could have possibly come up with such a precise measurement of pi with such ancient tools. I still don't really know how they did it, but today I found pi myself, so my brain doesn't feel as obligated as it did to figure out the old guys' ways.

To find pi, I used what is called a Monte Carlo method.  There are many ways to describe and use a Monte Carlo, but the simplest way (and the way I used it today) is to pick random numbers and analyze where they "fall." I say "fall" because this was called the "dart throwing" method when we were given our instructions.  I'm going to walk you through how I threw my darts.

First, let's start with a unit square, which is a square where each side has length 1.


And let's add a circle in that square, because we know since we're dealing with pi that we probably need a circle.


If I start randomly throwing "darts" at this image, what is the probability that it will land in the circle? It's the area of the circle over the area of the square. This makes sense, right? The bigger the circle, the better my chances are of hitting the circle with a dart. (I'm terrible at darts, so I'd need a really big circle to even hit it once. Luckily, my computer is way better at darts than I am.) More precisely, the probability is

$Prob = \frac{A_{circ}}{A_{square}} = \frac{\pi}{4} \rightarrow \pi = 4\frac{A_{circ}}{A_{square}}$

But, remember, the circle and square are imaginary. We don't really know their areas.  We just know (or we can find out) how many points fall in each. So the probability becomes 

$Prob = \frac{N_{circ}}{N_{square}}$

where N is the number of points in the region of interest. 

How do I find the number of points in the circle and square? Well, the square's easy.  Every point falls within the square, because the points that are in the circle are also in the square. The circle is trickier.  I have to make sure that the center of the circle is at (0,0).  This can be done by generating your random point values on an interval from -R to R.  Next, test each point, or dart, to see if its distance from the center is greater or less than R.  If it's less than R, the point is in the circle. 


And that's it!  By throwing enough darts (like, around 10000 or a million), I can eventually get to a really accurate value for pi.  Sure, my entire calculation is based on prior knowledge of the relationship between pi and the area of the circle, but you gotta start somewhere, right?

No comments:

Post a Comment