Tuesday 12 March 2019

Pi Day 2019 –Shooting Arrows at a Target to Calculate PI


Pi Day 2019 –Shooting Arrows at a Target to Calculate PI


It can be amusing to produce simple Monte Carlo simulations in Excel, and such simulations can be useful for many things, such as numerical solutions for integrals of functions.  Excel is probably not the most elegant or efficient program to use, but it is quick and easy to see what is going on, without needing any actual programming per se.

One such simulation can be used to estimate the value of Pi.  It is a simple matter:
·       Create a random set of X and Y coordinates between -1 and +1.
·       Calculate the Euclidean distance of each set of coordinates from the origin (i.e. use the Pythagorean Theorem of D=sqrt(X*X + Y*Y).
·       Determine whether the point is within the unit circle (D<=1), or outside of the unit circle.  Count the cases for each.
·       Determine (in/(in + out)), multiply that by 4 and that’s your estimate of Pi.  In other words, this will be the ratio of a unit circle that is inscribed in a unit square.

Here is a graph of one run of the simulation, using 1000 points, along with some results.



Granted, this 1000 point run resulted in a pretty rough estimate of Pi (3.18 vs 3.14, or about a 1% error).  However, if you had a computer with enough memory, you could estimate pi to as many decimal places as you liked with this method, by increasing the number of points used.  Be warned though; it converges very slowly, so you would need an awesome computer and/or a lot of time.

If we do 100 runs, using this technique, we get the following picture.  As you can see, the majority of the estimates are within 1% of the true value of Pi, though some are very close, and some are quite far.  



Looking at a histogram of the above results we see that the mean value is now much closer to PI, a result expected from the Central Limit Theorem (though a lot more runs of the experiment are obviously needed before the graph takes on the classic Gaussian shape - i.e. Bell Curve).



If we step up the number of points in the simulation, the estimate of Pi improves quite substantially.  Using about a million points, the error was generally within about .005%, as the graph below shows.



If we do a histogram of these 100 runs of 1 million points, we get the picture below.



Stepping up our 100 run simulation from 1000 points to 1,000,000 points per run increased our accuracy of PI by about 100 times, if we take the mean value for each experiment (from .094% to .001%).  That’s more than I would have expected – my initial thought was that the accuracy should go up by about 30 times (the square root of 1 million over the square root of one thousand).  There’s probably a good explanation for this, but I’m in a hurry to finish the blog by Pi Day, so that may remain a mystery for the reader to ponder.

Using our million point estimate of PI, our average estimate is 3.14163, which is close to the usual approximation of Pi that most of us can actually remember, 3.14159.  So, that’s good to within one part of one hundred thousand.  For most engineering purposes, that’s probably good enough.  For example, if you were digging a 1 km tunnel, and needed an accurate value of Pi to calculate an angle of attack, that would give you an error of only 1 centimeter over that distance.

Here’s what Herbert Schubert, a math prof, said in 1889 about the actual need for accuracy in determining the value of Pi, and the practical futility of calculating Pi to tremendous accuracy:

Conceive a sphere constructed with the earth at its center, and imagine its surface to pass through Sirius, which is 8.8 light years distant from the earth [that is, light, traveling at a velocity of 186,000 miles per second, takes 8.8 years to cover this distance]. Then imagine this enormous sphere to be so packed with microbes that in every cubic millimeter millions of millions of these diminutive animalcula are present. Now conceive these microbes to be unpacked and so distributed singly along a straight line that every two microbes are as far distant from each other as Sirius from us, 8.8 light years. Conceive the long line thus fixed by all the microbes as the diameter of a circle, and imagine its circumference to be calculated by multiplying its diameter by π to 100 decimal places. Then, in the case of a circle of this enormous magnitude even, the circumference so calculated would not vary from the real circumference by a millionth part of a millimeter. This example will suffice to show that the calculation of π to 100 or 500 decimal places is wholly useless.

Beckmann, Petr. A History of Pi (p. 101). St. Martin's Press. Kindle Edition.

That being said, the estimate from this method is still pathetic compared to what can be given by other methods, especially numeric methods, such as the many convergent infinite series, or even the Archimedean technique of inscribing nesting polygons within circles.

Still, this is a method that could have been used in the ancient world (I am not saying it was, it’s just an interesting thought experiment).  One could imagine a pharaoh directing his priests to perform such an experiment, perhaps by getting archers to shoot at a distant square target, and counting hits within the inscribed circle versus outside of the circle.



The archers would have to be instructed to not aim at the center, of course, as that would bias the results (maybe a “rain of arrows”, as at Agincourt, would be best).  And, the 1000 arrow experiment repeated 100 times is feasible – but even a powerful pharaoh would be hard pressed to do the million arrow experiment.  Though they did some amazing things, like building vast pyramids, when properly motivated. With a sufficiently mathematically inclined god to propitiate, you never know.  Perhaps there is a planet out there, where this has taken place.

And here are a couple of other Pi Day posts that I have done, with similar Pi-related experiments:
Calculating Pi from Probability Theory (Buffon’s Needle): https://dodecahedronbooks.blogspot.ca/2017/03/pi-day-floor-pie-and-floor-pi.html


Calculating Pi via Nested Polygons:



And as always (courtesy of my wife's excellent pumpkin pies, who also wrote the Kati of Terra and Witches' Stones series, shown below, which you should consider reading, too):




Sources:
Beckmann, Petr. A History of Pi (p. 101). St. Martin's Press. Kindle Edition.

 

So, now that you have done some math, you should read a science fiction book, or even better, a whole series.  Book 1 of the Witches’ Stones series even includes a reference to pi.:

Kati of Terra

How about trying Kati of Terra, the 3-novel story of a feisty young Earth woman, making her way in that big, bad, beautiful universe out there. 


The Witches’ Stones

Or, you might prefer, the trilogy of the Witches’ Stones (they’re psychic aliens, not actual witches), which follows the interactions of a future Earth confederation, an opposing galactic power, and the Witches of Kordea.  It features Sarah Mackenzie, another feisty young Earth woman (they’re the most interesting type – the novelist who wrote the books is pretty feisty, too).




The Magnetic Anomaly: A Science Fiction Story

“A geophysical crew went into the Canadian north. There were some regrettable accidents among a few ex-military who had become geophysical contractors after their service in the forces. A young man and young woman went temporarily mad from the stress of seeing that. They imagined things, terrible things. But both are known to have vivid imaginations; we have childhood records to verify that. It was all very sad. That’s the official story.”





The Zoo Hypothesis or The News of the World: A Science Fiction Story

In the field known as Astrobiology, there is a research program called SETI, The Search for Extraterrestrial Intelligence. At the heart of SETI, there is a mystery known as The Great Silence, or The Fermi Paradox, named after the famous physicist Enrico Fermi. Essentially, he asked “If they exist, where are they?”.

Some quite cogent arguments maintain that if there was extraterrestrial intelligence, they should have visited the Earth by now. This story, a bit tongue in cheek, gives a fictional account of one explanation for The Great Silence, known as The Zoo Hypothesis. Are we a protected species, in a Cosmic Zoo? If so, how did this come about? Read on, for one possible solution to The Fermi Paradox.

The short story is about 6300 words, or about half an hour at typical reading speeds.





No comments:

Post a Comment