How to Calculate Pi

π (pi) is the ratio between a circle’s circumference and it’s diameter. You can check this by using a tape measure. Measure around a circle. Then measure across the circle.

π = Around / Across

Did you know there is a way to calculate π? There are a lot of different ways, but one is called the Leibniz formula for π.

http://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80

Where the original Leibniz formula for π ends up calculating π/4, I’ve just factored this 4 into the infinite series.

π = 4/1 – 4/3 + 4/5 – 4/7 + 4/9 – 4/11 + 4/13 – 4/15 + 4/17 – … (forever)

The more terms you add/subtract to it, the closer it gets to being accurate. A problem with the Leibniz formula for π is that it takes a lot of calculations to get an accurate version of pi.

Here is a mini-program I wrote in Python 3 to repeat this one million times.

pi = 0
for n in range(1000000):
  pi += ((-1)**n*4) / (2*n+1)
print(pi)

Here are some of the numbers from that calculation:
4.00
2.66
3.46
2.89
3.33
2.97
3.28
3.01
3.25
3.04
3.23
3.05
3.21
3.07
3.20
3.07
3.20
3.08
3.19
3.09
3.18
…999980 more times…
3.1415916535897

Here is real PI:
3.1415926535897

Isn’t it interesting that my version of PI, after a million iterations, is 1 digit off of real Pi, but the digit is in the middle? This has something to do with Euler numbers which you can read about at http://en.wikipedia.org/wiki/Euler_number .

For most practical purposes, 3.14159 is more than enough digits to use with Pi.

Ever wonder if you could use Pie to calculate Pi?
http://www.numberphile.com/videos/pie_with_pies.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s