HYPERBALL_VOLUME_MONTE_CARLO is a C++ program which investigates the behavior of a Monte Carlo procedure when it is applied to compute the integral of a discontinuous function. In particular, our integration region is the M-dimensional unit hypercube and our function f(x) is 1 if the point x is inside the unit hyperball of radius 1, and 0 otherwise.
The program uses the Monte Carlo method to estimate the volume. Estimates are made starting with 2^0 (=1) points and doubling repeatedly up to 2^25 points.
Because the integrand is discontinuous, any quadrature rule based on the idea of interpolation will probably be unable to do a good job. A family of quadrature rules, which rely on increasing the order of interpolation to improve accuracy, will probably get increasingly bad answers.
By contrast, a basic Monte Carlo rule, which assumes nothing about the function, integrates this function just as well as it integrates most any other square-integrable function. (That's both the strength and weakness of the blunt instrument we call Monte Carlo integration.)
hyperball_volume_monte_carlo dim_num seedwhere
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
HYPERBALL_VOLUME_MONTE_CARLO is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version.
BALL_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate integrals of a function over the interior of the unit ball in 3D;
CIRCLE_MONTE_CARLO, a C++ library which uses the Monte Carlo method to estimate integrals over the circumference of the unit circle in 2D.
CUBE_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate the integral of a function over the interior of the unit cube in 3D;
DISK_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate the integral of a function over the interior of the general disk in 2D;
DISK01_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate the integral of a function over the interior of the unit disk in 2D;
DISK01_QUARTER_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate the integral of a function over the interior of the unit quarter disk in 2D;
ELLIPSE_MONTE_CARLO a C++ library which uses the Monte Carlo method to estimate the value of integrals over the interior of an ellipse in 2D.
ELLIPSOID_MONTE_CARLO a C++ library which uses the Monte Carlo method to estimate the value of integrals over the interior of an ellipsoid in M dimensions.
HYPERBALL_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate the integral of a function over the interior of the unit hyperball in M dimensions;
HYPERBALL_VOLUME_MONTE_CARLO, a FORTRAN90 program which applies a Monte Carlo method to estimate the volume of the unit hyperball in M dimensions;
HYPERCUBE_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate the integral of a function over the interior of the unit hypercube in M dimensions;
HYPERSPHERE_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate the integral of a function on the surface of the unit hypersphere in M dimensions;
LINE_MONTE_CARLO, a C++ library which uses the Monte Carlo method to estimate integrals over the length of the unit line in 1D.
POLYGON_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate the integral of a function over the interior of a polygon in 2D.
PYRAMID_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate integrals of a function over the interior of the unit pyramid in 3D;
SIMPLEX_MONTE_CARLO, a C++ library which uses the Monte Carlo method to estimate integrals over the interior of the unit simplex in M dimensions.
SPHERE_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate the integral of a function on the surface of the unit sphere in 3D;
SPHERE_TRIANGLE_MONTE_CARLO, a C++ library which applies a Monte Carlo method to estimate the integral of a function over a spherical triangle on the surface of the unit sphere in 3D;
SQUARE_MONTE_CARLO, a C++ library which uses the Monte Carlo method to estimate integrals over the interior of the unit square in 2D.
TETRAHEDRON_MONTE_CARLO, a C++ library which uses the Monte Carlo method to estimate integrals over the interior of the general tetrahedron in 3D.
TETRAHEDRON01_MONTE_CARLO, a C++ library which uses the Monte Carlo method to estimate integrals over the interior of the unit tetrahedron in 3D.
TRIANGLE_MONTE_CARLO, a C++ library which uses the Monte Carlo method to estimate integrals over the interior of a general triangle in 2D.
TRIANGLE01_MONTE_CARLO, a C++ library which uses the Monte Carlo method to estimate integrals over the interior of the unit triangle in 2D.
WEDGE_MONTE_CARLO, a C++ library which uses the Monte Carlo method to estimate integrals over the interior of the unit wedge in 3D.
You can go up one level to the C++ source codes.