How is Pi calculated?

589 views

Ok, pi is probably a bit over the head of your average 5 year old. I know the definition of pi is circumference / diameter, but is that really how we get all the digits of pi? We just get a circle, measure it and calculate? Or is there some other formula or something that we use to calculate the however many known digits of pi there are?

In: 716

28 Answers

Anonymous 0 Comments

While not strictly speaking a calculation, I think the monte carlo method is kind of cute.

Take a square with sides equal to 2. Inscribe a circle inside such that it touches all four sides. The circle will have a radius of 1 (it has a diameter of 2).

The square will have an area of 2^2 = 4

The circle will have an area of pi*r^2 = pi * (1^2) = pi

The ratio of the circle’s area to the square’s area is just pi / 4.

This means that if we picked a random point inside the square, the chance of it being inside the circle is pi/4.

Algorithm:

1) Set InsideCircle counter to 0

2) Set InsideSquare counter to 0

3) Repeat the following many times. The greater the number of repetitions the better your approximation will be (assuming you’re truly picking random numbers):

a) Pick a random point inside the square. You do this by picking two random values from -1 to 1. One value is the point’s x position, and the other is it’s y position. We are making the origin (0,0) the center of both our square and circle to make the maths easier.

b) Since this value is inside the square, increment the InsideSquare counter by 1.

c) Calculate the distance of this point from the origin. If it is less than 1 then it inside the circle (the circle had a radius of 1 and is located at the origin). d = sqrt(x^2 + y^2) where x and y are the two values we picked in step a.

d) If d < 1 then increment InsideCircle counter by 1

e) Calculate approximation of pi. As mentioned earlier, the ratio of inside circle to inside square is pi/4, so pi is 4 times this value. In other words: pi ~= 4 * (InsideCircle / InsideSquare)

We’ve just estimated pi by picking a whole bunch of random numbers.

You are viewing 1 out of 28 answers, click here to view all answers.