Happy Pi Day! Isn't Pi Day one of the best holidays all year? For last year's Pi Day, I determined a value of pi without even using a circle. How can you top that? I can top it by using pi to find pi. I know you are thinking: "WHATTT!!! YOU CAN'T DO THAT!" And just who do you think is going to stop me? That's right, no one. Here is the plan: Use the digits of pi to generate pseudo-random numbers. Plot these values as coordinates in an x-y plane. If the coordinate pair has a value of x2 + y2 less than 1, count it "inside a circle." Finally, the number of points "inside" to the total should be the same ratio as the area of a quarter of a circle to the area of a square.
This might be useful. It is an older post where I use the same method to determine pi (Monte Carlo method). Ok. Let's get to work. First, I need some pi. A lot of pi. This isn't too difficult. First google hit for "digits of pi" gave this link to 100,000 digits of pi. After saving that as a text file, I simple made a quick python program that takes 4 digits at a time (I cut off the first "3" -- I don't know why). Then made the four digits a "random" number between 0 and 1 alternating groups of 4 digits for x and y coordinates. For example, here are some of the first few digits of pi:
So, my first few "random" points would be:
- (0.1415, 0.9265)
- (0.3589, 0.7932)
- (0.3846, 0.2643)
You get the idea. Now for the plot. Here, I have made the data points that have a x2 + y2greater than 1 the color red. The other points are blue.
Just to be clear, the square has an "area" of 1 x 1 = 1. The quarter circle has an "area" of pi*(12)/4. I can assume (for random data) that the ratio of numbers of points in these two areas is the same ratio as the areas. Then find this number ratio and solve for pi. With this data, I get pi = 3.175294. Yes, that isn't super close to pi. Still, it was fun. How random are the digits of pi? I am not sure; let's find out. Here are some basic tests for randomness (Wikipedia). Some things to check. Are there equal numbers of 0's, 1's, 2's, etc.? You can do the same thing with double digit numbers (01, 02, 03, ..., 11, 12, ..., etc.). Then you can look at the number times you get five 3's in a row or something or the distances between successive zeros. Let me just first look at the distribution of these "random" numbers. Here is the data split into 10 bins.
I am pretty sure this is the same as the frequency test above - except for just the first digit of the 4-digit random number. Let me try breaking this into 100 bins.
Ok. That is a little more uneven. Maybe I should look at another distribution. Here are 25,000 points (same number) but generated from a python random number generator.
Looks about the same. Good enough for now.
Homework
I will let you take over the rest of this project. Here are some questions for you to answer.
- What if you use more digits of pi? Do you get a better answer?
- Compare this value of pi to the same calculation with 25,000 random numbers (not generated from the digits of pi).
- What if you generate 20,000 five-digit numbers (like 0.12345) instead of 25,000 four-digit numbers? Will this make a difference?
- Further explore the randomness of the digits of pi.
There you go. Maybe those answers will lead to next year's post for Pi Day. I wonder what it will be.
Homepage Photo: GJ/Wikimedia