Monte Carlo integration output

Integration Using Monte Carlo Simulation

Monte Carlo integration can be used to estimate integrals that cannot be easily solved by analytical methods.  There are several methods to apply Monte Carlo integration for finding integrals.  In this article we will cover the basic method.

Basic Monte Carlo Integration

The basic method of Monte Carlo integration randomly samples the function value on the interval over which we are integrating.  We determine a mean value of the function over the interval from the simulation.  Once we have the mean value, we multiply by the ranges of each dimension.

For the simple case of a one dimensional function, f(x), a Monte Carlo simulation of the function over the desired interval [a,b] is performed and the mean function value, fm, is determined.  To find the area under the curve we use the following equation for the area of a rectangle:

f(x)dx = (b-a)fm   for a ≤ x ≤ b

For a more general multi-dimensional case, f(x,y,z), a Monte Carlo simulation of the function over the desired intervals [ax,bx], [ay,by], and [az,bz] is performed and the mean function value, fm, is determined.  To estimate the integral we use the following equation:

∫∫∫f(x,y,z)dzdydx = (bx-ax)(by-ay)(bz-az)fm   for ax ≤ x ≤ bx, ay ≤ y ≤ by, az ≤ z ≤ bz

Error Estimation

Monte Carlo methods are an approximation of the integral.  The question arises as to how many iterations do we need to simulate?  The error involved can be estimated by the following equation where N is the number of simulation iterations.

Error = 1/√N

As you might expect, increasing the number of iterations reduces the error since more function points are simulated.

A Multi-Dimensional Example

We will estimate the integral with a known answer to illustrate how to perform a Monte Carlo integration using Simulation Master.  Suppose we have the following triple integral (the answer determined analytically is 6)*.

∫∫∫xy sin z dzdydx

in the region 0 ≤ x ≤ 2, 1 ≤ y ≤ 2, 0 ≤ z ≤ π

A spreadsheet is created to generate random values in the ranges for each variable. The function value is calculated as the output cell and we simulate this for the desired number of iterations.

Spreadsheet with Formulas Shown

After running the simulation we can find the mean value of the function.  In this example, it is 0.9556.

Simulation Output

We then plug the mean value into the spreadsheet to find the answer.  As shown in the spreadsheet below, our estimate is 6.0011 which is close to 6.

Integration Spreadsheet

To illustrate error estimation, we compare estimated error to actual error from the simulation.  The estimated error is 0.00472 and the actual error from this simulation is 0.000195 which is considerably less than the estimate.  Due to the random nature of the inputs, actual error will vary each time the simulation is run.

The Monte Carlo integration was performed using Simulation Master.  For more information, visit the Simulation Master product page.

*This problem is from Calculus and Analytic Geometry, 1983, Faires and Faires, PWS Publishers, pages 888-889.