This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

NIntegrate Introduction


The Mathematica function NIntegrate is a general numerical integrator. It can handle a wide range of one-dimensional and multidimensional integrals.
find a numerical integral for the function f over the region [a1, b2]×[a2, b2...×[an, bn]

Finding a numerical integral of a function over a region.

In general, NIntegrate estimates the integral through sampling of the integrand value over the integration region. The various numerical integration methods prescribe how this sampling is done: what its initial steps are, and how it evolves.
NIntegrate uses algorithms called "integration strategies" that attempt to compute integral estimates that satisfy user-specified precision or accuracy goals. The integration strategies use "integration rules" that compute integral estimates using weighted sums.
This numerically computes the integral .
Click for copyable input
NIntegrate uses symbolic preprocessing that simplifies integrals with piecewise functions and even or odd functions. Part of the symbolic preprocessing is the detection of one-dimensional oscillatory integrals of the types NIntegrate can handle efficiently.
This integrates a piecewise function over the interval [0, 2].
Click for copyable input
This integrates a highly oscillatory function over the interval [2, 3].
Click for copyable input
This is a plot of the previous oscillatory integrand over of the integration region.
Click for copyable input
This integrates a piecewise combination of a piecewise function and an oscillatory function.
Click for copyable input
NIntegrate oscillatory algorithms are only for one-dimensional integrals. The oscillatory algorithms for finite regions are different from the oscillatory algorithms for infinite regions.
One-dimensional numerical integration is much simpler, and better understood, than multidimensional numerical integration. This is the reason a distinction between the two is made. All NIntegrate strategies except the oscillatory strategies can be used for multidimensional integration.
Here is a two-dimensional function: a cone with base in the square [-1, 1]×[-1, 1].
Click for copyable input
Here is the integral of the cone function.
Click for copyable input
Here are the sampling points used by NIntegrate. Note that the sampling points are only in a quarter of the integration region.
Click for copyable input
Here are the sampling points used by NIntegrate without symbolic preprocessing. (The reason that NIntegrate gives the slwcon message is because no symbolic preprocessing is applied.) Note that the sampling points are in the whole integration region and that they are denser around the circumference of the cone base and around the cone apex.
Click for copyable input
NIntegrate has several ways to deal with singular integrands. The deterministic adaptive strategies "GlobalAdaptive" and "LocalAdaptive" use singularity handling techniques (based on variable transformations) to speed up the convergence of the integration process. The strategy "DoubleExponential" employs trapezoidal quadrature with a special variable transformation on the integrand. This rule-transformation combination achieves optimal convergence for integrands analytic on an open set in the complex plane containing the interval of integration. The strategy "DuffyCoordinates" simplifies or eliminates certain types of singularities in multidimensional integrals.
Here is a one-dimensional integration with singularity handling.
Click for copyable input
Without singularity handling the previous integral is computed more slowly.
Click for copyable input
For multidimensional integrands that have certain spherical symmetry the strategy "DuffyCoordinates" converges quite fast.
Here is a "DuffyCoordinates" integration.
Click for copyable input
Here is a computation of the previous integral with the default settings; it is approximately 5 times slower.
Click for copyable input
The "Trapezoidal" strategy gives optimal convergence for analytic periodic integrands when the integration interval is exactly one period.
Here is a calculation of an integral computed with the trapezoidal strategy. The result is compared with the exact value. The result computed with "Trapezoidal" is obtained faster and it is more precise than the one with default NIntegrate settings.
Click for copyable input
Click for copyable input
Click for copyable input
Here is a (slower) computation of then same integral but with the default Method settings for NIntegrate.
Click for copyable input
Click for copyable input
For multidimensional integrals, or in cases when only a rough integral estimate is needed, Monte Carlo methods are useful. NIntegrate has both crude and adaptive Monte Carlo and quasi Monte Carlo strategies.
Here is a multidimensional integral done quickly with a Monte Carlo algorithm.
Click for copyable input



The principal features of the NIntegrate framework are:
  • Code reuse (common code base)
  • Object orientation (method property specification and communication)
  • Data hiding
  • Separation of method initialization phase and runtime computation
  • Hierarchical and reentrant numerical methods
  • Type- and precision-dynamic methods
  • User extensibility and prototyping through plug-in capabilities
  • Specialized data structures

Strategies, rules, and preprocessors

NIntegrate strategies can be divided into two general groups: deterministic and Monte Carlo. Each group can be divided further into adaptive, non-adaptive, and specialized strategies. Adaptive strategies try to improve the integral estimate by concentrating their efforts around the problematic areas. Non-adaptive strategies try to improve the integral estimate just by increasing the number of sampling points in the integration region. Specialized strategies are made for certain types of integrals (e.g., a product of an oscillatory and a non-oscillatory function).

NIntegrate built-in integration strategies.

The strategies "GlobalAdaptive" and "LocalAdaptive" can have specifications of what integration rules to use.
Here is an example of "GlobalAdaptive" with an integration rule specification.
Click for copyable input
Both "GlobalAdaptive" and "LocalAdaptive" adaptive strategies can be used with one-dimensional and multidimensional integration rules.

Built-in integration rules that can be used by "GlobalAdaptive" and "LocalAdaptive".

The capabilities of all strategies are extended through integral preprocessing. The preprocessors can be seen as strategies that delegate integration to other strategies (preprocessors included).
Here is an example of the preprocessing of an integrand which is even with respect to each of its variables.
Click for copyable input
Here are the sampling points of the previous integration. If no preprocessing had been done, the plot would have been in the region [-1, 1]×[-1, 1] with a symmetry along both the x axis and the y axis.
Click for copyable input

NIntegrate preprocessors.

User extensibility

Built-in methods can be used as building blocks for the efficient construction of special-purpose integrators. User-defined integration rules and strategies can also be added.