This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
 Mathematica Tutorial

# NIntegrate Introduction

## Overview

The Mathematica function NIntegrate is a general numerical integrator. It can handle a wide range of one-dimensional and multidimensional integrals.
 NIntegrate[f[x1,x2,...,xn],{x1,a1,b1},{x2,a2,b2},...,{xn,an,bn}] 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 .
 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 one-dimensional 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 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].
 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 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.
 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]=
Here is a (slower) computation of then same integral but with the default Method settings for NIntegrate.
 Out[38]=
 Out[39]=
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)
• 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.
 Out[21]=
Both "GlobalAdaptive" and "LocalAdaptive" adaptive strategies can be used with one-dimensional and multidimensional integration rules.
 Rules one-dimensional "BooleRule" "ClenshawCurtisRule" "GaussBerntsenEspelidRule" "GaussKronrodRule" "LobattoKronrodRule" "LobattoPeanoRule" "MultiPanelRule" "NewtonCotesRule" "PattersonRule" "SimpsonThreeEightsRule" "TrapezoidalRule" multidimensional "CartesianRule" "MultiDimensionalRule"

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.
 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]=
 preprocessors "SymbolicPiecewiseSubdivision" "EvenOddSubdivision" "OscillatorySelection" "UnitCubeRescaling"

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.