Skip to content
/ pi Public

Small program in C language to calculate pi value.

License

Notifications You must be signed in to change notification settings

BaseMax/pi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pi

Small program in C language to calculate pi value.

If you write another program to calculate pi value in another way, please send PR.

Calculating Pi (π)

Because Pi (π) has so many important uses, then we need to be able to start to calculate it, at least to several decimal places accuracy. Someone had to come up with the approximate value for Pi (π) which appears on your calculator – it didn’t get there by magic!

Easy and good article: https://www.wikihow.com/Calculate-Pi and https://www.mathsisfun.com/numbers/pi.html

Measuring circles

The first and most obvious way to calculate Pi (π) is to take the most perfect circle you can, and then measure its circumference and diameter to work out Pi (π). This is what ancient civilisations would have done and it is how they would have first realised that there is a constant ratio hidden within every circle. The problem with this method is accuracy – can you trust your tape measure to deliver Pi (π) correct to 10 or more decimal places?

HexagonsUsing Polygons to approximate Pi (π)

The Ancient Greek mathematician Archimedes came up with an ingenious method for calculating an approximation of Pi (π). Archimedes began by inscribing a regular hexagon inside a circle and then circumscribing another regular hexagon outside the same circle. He was then able to calculate the exact circumferences and diameters of the hexagons and could therefore obtain a rough approximation of Pi (π) by dividing the circumference by the diameter.

Archimedes then found a way to double the number of sides of his hexagons. He could then find a more accurate approximation of Pi (π) by using polygons with more sides, which were closer to the circle. He did this four times until he was using 96 sided polygons. Archimedes calculated the circumference and diameter exactly and therefore could approximate Pi (π) to being between\frac{223}{71} and \frac{22}{7}. The fraction \frac{22}{7} has remained as one of the most popular and memorable approximations of Pi (π) ever since.

Around 600 years after Archimedes, the Chinese mathematician Zu Chongzhi used a similar method to inscribe a regular polygon with 12,288 sides. This produced an approximation of Pi (π) as \frac{355}{113} which is correct to six decimal places. It was nearly 600 more years until a totally new method was devised that improved upon this approximation.

Calculating Pi (π) using infinite series

Mathematicians eventually discovered that there are in fact exact formulas for calculating Pi (π). The only catch is that each formula requires you to do something an infinite number of times. (Which makes sense given that the digits of Pi (π) go on forever.) One of the amazing things which interests people about Pi (π) is that there isn’t just one formula, but a large number of different ones for people to study.

One of the most well known and beautiful ways to calculate Pi (π) is to use the Gregory-Leibniz Series:

\frac{\pi}{4}=1-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}+\frac{1}{9}-\ldots

If you continued this pattern forever you would be able to calculate \frac{\pi}{4} exactly and then just multiply it by 4 in order to get \pi.. If however you start to add up the first few terms, you will begin to get an approximation for Pi (π). The problem with the series above is that you need to add up a lot of terms in order to get an accurate approximation of Pi (π). You need to add up more than 300 terms in order to produce Pi (π) accurate to two decimal places!

Another series which converges more quickly is the Nilakantha Series which was developed in the 15th century. Converges more quickly means that you need to work out fewer terms for your answer to become closer to Pi (π) .

Nilakantha Series

Mathematicians have also found other more efficient series for calculating Pi (π). Computer programs can add up more and more terms, calculating Pi (π) to extraordinary degrees of accuracy. In 2014 the world record was that a computer has calculated Pi (π) correct to 13,300,000,000,000 decimal places.

\pi= 3+ \frac{4}{2\times 3 \times 4}-\frac{4}{4\times 5 \times 6}+\frac{4}{6\times 7 \times 8}-\frac{4}{8\times 9 \times 10}+\ldots

Before the advent of computers it was much harder to calculate Pi (π). In the 19th Century William Shanks took 15 years to calculate Pi (π) correct to 707 decimal places. Unfortunately it was later found that he had made a mistake and was only right to 527 decimal places! The nine or 10 digits of Pi (π) which you see on your calculator have been known about probably since 1400.

Now that you know how to calculate Pi (π), you could always try your hand at memorising the decimal places of Pi (π). The most recent record was created on Pi Day in 2019 by Google, who calculated Pi to 31.4 trillion decimal places!. On the other hand, you could simply use the following mnemonic for learning the first six decimal places of Pi (π): “How I wish I could calculate Pi”

Read more: https://www.mathscareers.org.uk/article/calculating-pi/

Monte Carlo

Read MonteCarlo-1.pdf and MonteCarlo-2.pdf article.


Max Base

My nickname is Max, Programming language developer, Full-stack programmer. I love computer scientists, researchers, and compilers. (Max Base)

Asrez Team

A team includes some programmer, developer, designer, researcher(s) especially Max Base.

Asrez Team

Releases

No releases published

Packages

No packages published

Languages