NIntegrate Introduction
Overview
The
Mathematica function
NIntegrate is a general numerical integrator. It can handle a wide range of onedimensional and multidimensional integrals.
NIntegrate[f[x_{1},x_{2},...,x_{n}],{x_{1},a_{1},b_{1}},{x_{2},a_{2},b_{2}},...,{x_{n},a_{n},b_{n}}] 
 find a numerical integral for the function f over the region [a_{1}, b_{2}]×[a_{2}, b_{2}]×...×[a_{n}, b_{n}] 
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 userspecified precision or accuracy goals. The
integration strategies use
"integration rules" that compute integral estimates using weighted sums.
This numerically computes the integral .
Out[25]=  

NIntegrate uses symbolic preprocessing that simplifies integrals with piecewise functions and even or odd functions. Part of the symbolic preprocessing is the detection of onedimensional oscillatory integrals of the types
NIntegrate can handle efficiently.
This integrates a piecewise function over the interval [0, 2].
Out[26]=  

This integrates a highly oscillatory function over the interval [2, 3].
Out[27]=  

This is a plot of the previous oscillatory integrand over of the integration region.
Out[28]=  

This integrates a piecewise combination of a piecewise function and an oscillatory function.
Out[29]=  

NIntegrate oscillatory algorithms are only for onedimensional integrals. The oscillatory algorithms for finite regions are different from the oscillatory algorithms for infinite regions.
Onedimensional 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 twodimensional function: a cone with base in the square [1, 1]× [1, 1].
Out[30]=  

Here is the integral of the cone function.
Out[7]=  

Here are the sampling points used by NIntegrate. Note that the sampling points are only in a quarter of the integration region.
Out[8]=  

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.
Out[9]=  

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 ruletransformation 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 onedimensional integration with singularity handling.
Out[2]=  

Without singularity handling the previous integral is computed more slowly.
Out[3]=  

For multidimensional integrands that have certain spherical symmetry the strategy
"DuffyCoordinates" converges quite fast.
Here is a "DuffyCoordinates" integration.
Out[12]=  

Here is a computation of the previous integral with the default settings; it is approximately 5 times slower.
Out[13]=  

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.
Out[5]=  
Out[37]=  
Out[40]=  

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.
Out[20]=  

Design
Features
The principal features of the
NIntegrate framework are:
 Code reuse (common code base)
 Object orientation (method property specification and communication)
 Separation of method initialization phase and runtime computation
 Hierarchical and reentrant numerical methods
 Type and precisiondynamic methods
 User extensibility and prototyping through plugin 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, nonadaptive, and specialized strategies. Adaptive strategies try to improve the integral estimate by concentrating their efforts around the problematic areas. Nonadaptive 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 nonoscillatory function).
NIntegrate builtin 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.
Out[21]=  

Both
"GlobalAdaptive" and
"LocalAdaptive" adaptive strategies can be used with onedimensional and multidimensional integration rules.
Builtin 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.
Out[22]=  

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.
Out[23]=  


"SymbolicPiecewiseSubdivision" 
"EvenOddSubdivision" 
"OscillatorySelection" 
"UnitCubeRescaling" 
NIntegrate preprocessors.
User extensibility
Builtin methods can be used as building blocks for the efficient construction of specialpurpose integrators. Userdefined integration rules and strategies can also be added.