# NIntegrate Introduction

## Overview

The Wolfram Language function NIntegrate is a general numerical integrator. It can handle a wide range of one-dimensional 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 |

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 the initial sampling steps and how the sampling evolves.

In[38]:= |

Out[38]= |

In[19]:= |

Out[19]= |

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 a single integral estimate from a set of integrand values, often using a weighted sum.

In[26]:= |

Out[26]= |

### Symbolic Preprocessing

NIntegrate uses symbolic preprocessing to simplify integrals with special structure and to automatically select integration methods. Integrands that are even or odd functions or that contain piecewise functions may lead to the integration region being transformed or separated into multiple distinct integration regions.

In[43]:= |

Out[43]= |

Highly oscillatory integrands are identified and specialized integration rules are applied.

In[41]:= |

Out[41]= |

In[23]:= |

Out[23]= |

Symbolic preprocessing allows the automatic computation of a wide variety of integrals containing discontinuities and regions of extremely rapid variation.

In[28]:= |

Out[28]= |

### Quadrature Rules

NIntegrate includes most classical one-dimensional quadrature rules.

In[10]:= |

Out[10]= |

The classical quadrature rules work by forming a linear combination of the sampled integrand values. The vector of weights in the linear combination is fixed for each quadrature rule.

In[28]:= |

Out[28]= |

For multidimensional integrals, NIntegrate includes a class of rules based on sparse grids and also allows rules formed from the Cartesian product of one-dimensional rules.

In[3]:= |

Out[3]= |

In[4]:= |

Out[4]= |

In[13]:= |

Out[13]= |

Boole can be used to specify more complicated multidimensional regions. Regions specified this way may also be further simplified during symbolic preprocessing.

In[30]:= |

Out[30]= |

In[7]:= |

Out[7]= |

In[50]:= |

In[52]:= |

Out[52]= |

In[55]:= |

Out[55]= |

### Oscillatory Integration

NIntegrate contains general oscillatory integration methods applicable to a very wide range of integrands, over finite or infinite regions, and in either one dimension or multiple dimensions. Additionally, NIntegrate contains several methods that are specifically suited to one-dimensional integrals of functions of particular forms involving Exp, trigonometric functions such as Sin and Cos, and certain other special functions such as BesselJ.

In[15]:= |

Out[15]= |

In[16]:= |

Out[16]= |

### Automatic Singularity Handling

NIntegrate has several ways to deal with singular integrands. The deterministic adaptive strategies and use singularity handling techniques (based on variable transformations) to speed up the convergence of the integration process. The strategy 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.

In[39]:= |

Out[39]= |

In[40]:= |

Out[40]= |

In[41]:= |

Out[41]= |

### Special Strategies

The strategy simplifies or eliminates certain types of singularities in multidimensional integrals. Integrals with certain spherical symmetry can converge very quickly.

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]= |

The strategy gives optimal convergence for analytic periodic integrands when the integration interval is exactly one period.

In[5]:= |

Out[5]= |

In[37]:= |

Out[37]= |

In[40]:= |

Out[40]= |

In[38]:= |

Out[38]= |

In[39]:= |

Out[39]= |

For high-dimensional 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.

In[19]:= |

Out[20]= |

### Design

The principal features of the NIntegrate framework are:

## Strategies, Rules, and Preprocessors

NIntegrate integration strategies can be classified according to how they sample the integration region, the class of integrands to which they can be applied, and whether they are "rule-based" strategies.

"GlobalAdaptive" | any integrand, adaptive sampling, rule-based |

"LocalAdaptive" | any integrand, adaptive sampling, rule-based |

"DoubleExponential" | any integrand, uniform sampling |

"Trapezoidal" | any integrand, uniform sampling |

"MultiPeriodic" | multidimensional integrand, uniform sampling |

"MonteCarlo" | any integrand, uniform random sampling |

"QuasiMonteCarlo" | any integrand, uniform quasi-random sampling |

"AdaptiveMonteCarlo" | any integrand, adaptive random sampling |

"AdaptiveQuasiMonteCarlo" | any integrand, adaptive quasi-random sampling |

"DoubleExponentialOscillatory" | one-dimensional infinite-range oscillatory integrand |

"ExtrapolatingOscillatory" | one-dimensional infinite-range oscillatory integrand |

NIntegrate integration strategies.

Adaptive sampling strategies try to improve the integral estimate by sampling more often in subregions with a larger error estimate, typically by subdividing those subregions. Uniform sampling strategies try to improve the integral estimate by uniformly increasing the density of sampling throughout the whole integration region.

Rule-based strategies apply a given integration rule to each subregion to obtain integral and error estimates for that region. The integration rule can be specified with the setting Method->{"strategy",Method->"rule"}.

In[21]:= |

Out[21]= |

NIntegrate integration rules can be classified according to whether they apply to one-dimensional or multidimensional regions, and according to the type of integration rule.

"BooleRule" | one-dimensional, weighted sum |

"ClenshawCurtisRule" | one-dimensional, weighted sum |

"GaussBerntsenEspelidRule" | one-dimensional, weighted sum |

"GaussKronrodRule" | one-dimensional, weighted sum |

"LobattoKronrodRule" | one-dimensional, weighted sum |

"LobattoPeanoRule" | one-dimensional, weighted sum |

"NewtonCotesRule" | one-dimensional, weighted sum |

"TrapezoidalRule" | one-dimensional, weighted sum |

"ClenshawCurtisOscillatoryRule" | one-dimensional, specialized oscillatory rule |

"LevinRule" | one- or multidimensional, general oscillatory rule |

"MultipanelRule" | one-dimensional, weighted sum, combination of 1D rules |

"CartesianRule" | multidimensional, weighted sum, product of 1D rules |

"MultidimensionalRule" | multidimensional, weighted sum |

Integration rules that can be used with the rule-based strategies and .

Classical "weighted sum"-type rules estimate the integral as a predetermined linear combination of the function values at a set of points. Oscillatory rules estimate the integral using quadrature weights that depend on the particular oscillatory "kernel" of the integrand.

Combination rules construct a quadrature rule from one or more subrules. They are specified with the setting Method->{"rule",Method->{"subrule_{1}",…}}.

In[4]:= |

Out[4]= |

The capabilities of all strategies are extended through symbolic preprocessing of the integrand. Preprocessing is controlled by preprocessor strategies that first transform or analyze the integral, then delegate integration to another strategy (often another preprocessor strategy).

"SymbolicPreprocessing" | overall preprocessor controller |

"EvenOddSubdivision" | simplify even and odd integrands |

"InterpolationPointsSubdivision" | subdivide integrands containing interpolating functions |

"OscillatorySelection" | detect oscillatory integrands and select suitable methods |

"SymbolicPiecewiseSubdivision" | subdivide integrands containing piecewise functions |

"UnitCubeRescaling" | rescale multidimensional integrand to unit cube |

"DuffyCoordinates" | multidimensional singularity-removing transformation |

"PrincipalValue" | numerical integral equivalent to Cauchy principal value |

NIntegrate preprocessor strategies.

Preprocessor strategies are specified with the setting Method->{"preprocessor",Method->m}, where m is the strategy or rule to which the integration is delegated after preprocessing is complete.

In[4]:= |

Out[4]= |

Preprocessor strategies often reduce the amount of work required by the final integration strategy.

In[15]:= |

Out[15]= |

### User Extensibility

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