Interactive Educational Modules in
Scientific Computing

Computing the Area of a Disk using Monte Carlo

This module estimates the area of the unit disk using the Monte Carlo method to approximate the integral of a function of two variables. The area of the unit disk is equal to the volume of a cylinder of height 1 having the unit disk as its base. That volume can be calculated as the integral of a function of two variables that takes the value 1 for points inside the unit disk and the value 0 for points of the circumscribing square outside the unit disk. This module applies the Monte Carlo method to approximate the integral of such a function.

The user first selects the number of sample points to be taken at a time (1 is the default). The user then clicks on Sample repeatedly to sample the circumscribing square at an additional set of randomly chosen points. The location of each sample point is shown in the graph by a small plus symbol. The symbol is red if the function value is 1 (the sample point is inside the disk) and blue if the value is 0 (the sample point is outside the disk). New samples are distinguished from previous samples by a darker shade. Numerical values are printed below for the correct integral I, the cumulative number of samples N, and the current estimate of the integral Q along with its error. The integral can be seen to converge very slowly to π (the area of the unit disk) as the number of samples increases.

Reference: Michael T. Heath, Scientific Computing, An Introductory Survey, 2nd edition, McGraw-Hill, New York, 2002. See Section 8.4.4 and Chapter 13.

Developers: Evan VanderZee and Michael Heath