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.
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
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]
This integrates a highly oscillatory function over the interval [2, 3]
This is a plot of the previous oscillatory integrand over
of the integration region.
This integrates a piecewise combination of a piecewise function and an oscillatory function.
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]
Here is the integral of the cone function.
Here are the sampling points used by NIntegrate
. Note that the sampling points are only in a quarter of the integration region.
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.
has several ways to deal with singular integrands. The deterministic adaptive strategies "GlobalAdaptive"
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.
Without singularity handling the previous integral is computed more slowly.
For multidimensional integrands that have certain spherical symmetry the strategy "DuffyCoordinates"
converges quite fast.
Here is a "DuffyCoordinates"
Here is a computation of the previous integral with the default settings; it is approximately 5 times slower.
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
Here is a (slower) computation of then same integral but with the default Method
settings for NIntegrate
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.
The principal features of the NIntegrate
- 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 precision-dynamic methods
- User extensibility and prototyping through plug-in capabilities
- Specialized data structures
Strategies, rules, and preprocessors
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"
can have specifications of what integration rules to use.
Here is an example of "GlobalAdaptive"
with an integration rule specification.
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.
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]
with a symmetry along both the x
axis and the y
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.