Calculate PI using 22/7. How many decimal places is this correct to?
Can you find a different division which is accurate to more decimal places?
Try using the Gregory-Leibniz series
π =
How many iterations do you need to get a number accurate to 5 decimal places?
Try using the Nilakantha series.
π =
Using random numbers!
Imagine you have a circle inscribed inside a square. You then throw darts at random at the square. The number of darts inside the circle divided the number of darts will then give you a value for PI.
Steps are...
- Assume the coordinates for your square run from -1,-1 (bottom-left) to 1,1 (top-right)
- Generate a random number for X which is between -1.0 and 1.0
- Generate a random number for Y which is between -1.0 and 1.0
- If the point X,Y is inside the unit circle then increase the HITS count by 1
- Increase the number of THROWS by 1
- The estimate for PI can be found by (HITS / THROWS) * 4
- Repeat the process
The following formula can be used to test if X,Y is inside the circle.
If Distance is < 1 then the dart is with the circle.
Plot some graphs showing the number of decimal places against the number of iterations.