Project: Compute π (Monte Carlo with Central Limit Theorem)
Write a program that computes and prints π using the Monte Carlo method. See ComputePi2. Compute π 20 times using the Monte Carlo method and take the average to get a better approximation. Use a function to encapsulate the Monte Carlo simulation.
The idea that the average of multiple trials yields a better approximation is called the [[Central Limit Theorem]]. Is this approach any better than just computing one estimate with a larger number of samples?
Output
$ python3 ComputePi4.py
PI0: 3.149200000000000
PI1: 3.137680000000000
PI2: 3.151600000000000
PI3: 3.135200000000000
PI4: 3.136480000000000
PI5: 3.139960000000000
PI6: 3.146200000000000
PI7: 3.143160000000000
PI8: 3.146160000000000
PI9: 3.144480000000000
PI10: 3.136920000000000
PI11: 3.142720000000000
PI12: 3.141520000000000
PI13: 3.139760000000000
PI14: 3.148720000000000
PI15: 3.135240000000000
PI16: 3.140120000000000
PI17: 3.138040000000000
PI18: 3.132840000000000
PI19: 3.138960000000000
PI: 3.141248000000000
abs(PI - π): 3.4465358979e-04