Univeristy of Alabama in Huntsville


IDL Routines from Phillip Bitzer and UAH Lightning Group

summary     class     fields     routine details     file attributes



ATS606, Stats, Integration, Monte Carlo

includes main-level program

In ATS606, we discuss how to integrate a function that is not analytically integrable. This function provides an example how this done, using the normal distribution.

The normal distribution, of course, is given by $$ f(x) = \frac{1}{\sqrt{2\pi}} e^{-x^2/2} $$

To find the probability a random draw from the distribution falls between $a,b$ we integrate: $$ Pr = \int_a^b f(x) dx = \int_a^b \frac{1}{\sqrt{2\pi}} e^{-x^2/2} dx $$

This is not, in general, integrable. But, the integral can be estimated with Monte Carlo methods. In general, an integral is estimated with: $$ I \approx (b-a)/n * \sum_i f(x_i) $$

where $a,b$ are the lower and upper limits of the integration, and $f(x)$ is the function you wish to integrate. The $x_i$ are random values of the integrand which are derived from the uniform distribution.


To estimate the integral of the normal distribution betwen -1 and 1, which we know should yield $0.683$, try this:

n = 1e2 ;number of random samples to use xMin = -1 & xMax = 1 int = ATS_MC_INTEGRATE_EXAMPLE(n, xMin=xMin, xMax=xMax) print, int
See the main level program for a (small) extension of this.

Author information


Phillip M. Bitzer, University of Alabama in Huntsville, pm.bitzer "AT" uah.edu


Modification History:

First written: Apr 9, 2014


top ats_mc_integrate_example

result = ats_mc_integrate_example( [num] [, xMin=float] [, xMax=float])

This estimates the integral of the normal distribution betwen the given limits. On error, a NaN is returned.

Return value

The value of the integral of the normal distribution between the given limits.


num in optional type=integer default=100

The number of samples used to estimate the integral.


xMin in optional type=float default=-1.

The lower limit of the integration

xMax in optional type=float default=1.

The upper limit of the integration

File attributes

Modification date: Wed Apr 16 12:06:44 2014
Lines: 27
Docformat: rst rst