Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is pi (π) calculated?

Tags:

algorithm

math

pi

How can I write a function which will return pi (π) to a given number of decimal places?

Speed is not a concern. I've been looking at http://bellard.org/pi/, but I still don't understand how to get the nth digit of pi.

like image 691
jmasterx Avatar asked Apr 16 '10 16:04

jmasterx


People also ask

How is pi value calculated?

What is the formula for calculating pi? The pi is a ratio and is obtained from a circle. If the diameter and the circumference of a circle are known, the value of pi will be as π = Circumference/ Diameter.

How did we get 3.14 for pi?

If you divide the circumference of the circle by the diameter, you will get approximately 3.14—no matter what size circle you drew! A larger circle will have a larger circumference and a larger radius, but the ratio will always be the same.


1 Answers

In calculus there is a thing called Taylor Series which provides an easy way to calculate many irrational values to arbitrary precision.

Pi/4 = 1 - 1/3 + 1/5 - 1/7 + ...
(from http://www.math.hmc.edu/funfacts/ffiles/30001.1-3.shtml )

Keep adding those terms until the number of digits of precision you want stabilize.

Taylor's theorem is a powerful tool, but the derivation of this series using the theorem is beyond the scope of the question. It's standard first-year university calculus and is easily googlable if you're interested in more detail.


I didn't mean to imply that this is the most practical method to calculate pi. That would depend on why you really need to do it. For practical purposes, you should just copy as many digits as you need from one of the many published versions. I was suggesting this as a simple introduction of how irrational values can be equated to infinite series.

like image 64
Alan Avatar answered Sep 29 '22 07:09

Alan