Monte Carlo method to compute an approximation to π - CS 222 Program 2
The program Your program will use a Monte Carlo method to compute an approximation to π. In a Monte Carlo computation a sequence of random values is generated and run through a model of a system. For our simple program the random values will be used to plot points as described below. You will generate a random sequence of points in the unit square in the coordinate plane and see how many fall inside the unit circle. In the following figure seven of ten randomly generated points fell inside the circle. 7/10 = 0.7 then gives a (very) rough approximation to the ratio: (area of circle segment)/(area of unit square) = π/4 Thus 0.7 is an approximation to π/4 so 4 × 0.7 = 2.8 is an approximation to π. Larger numbers of points will give better approximations. The program will use the above method to compute approxiations to π four times: using 10 points, 100 points, 1000 points, and 1000000 points. It will report the results of each of the computations with the number of points used, the compu...