Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Mathematics and Algorithms > Calculus >

NIntegrate

NIntegrate[f, {x, xmin, xmax}]
gives a numerical approximation to the integral .
NIntegrate[f, {x, xmin, xmax}, {y, ymin, ymax}, ...]
gives a numerical approximation to the multiple integral .
  • Multiple integrals use a variant of the standard iterator notation. The first variable given corresponds to the outermost integral, and is done last.
  • NIntegrate by default tests for singularities at the boundaries of the integration region, and at the boundaries of regions specified by settings for the Exclusions option.
  • NIntegrate[f, {x, x0, x1, ..., xk}] tests for singularities in a one-dimensional integral at each of the intermediate points xi. If there are no singularities, the result is equivalent to an integral from x0 to xk. You can use complex numbers xi to specify an integration contour in the complex plane.
  • The following options can be given:
AccuracyGoalInfinitydigits of absolute accuracy sought
EvaluationMonitorNoneexpression to evaluate whenever expr is evaluated
ExclusionsNoneparts of the integration region to exclude
MaxPointsAutomaticmaximum total number of sample points
MaxRecursionAutomaticmaximum number of recursive subdivisions
MethodAutomaticmethod to use
MinRecursion0minimum number of recursive subdivisions
PrecisionGoalAutomaticdigits of precision sought
WorkingPrecisionMachinePrecisionthe precision used in internal computations
  • NIntegrate usually uses adaptive algorithms, which recursively subdivide the integration region as needed. MinRecursion specifies the minimum number of recursive subdivisions to try. MaxRecursion gives the maximum number.
  • NIntegrate usually continues doing subdivisions until the error estimate it gets implies that the final result achieves either the AccuracyGoal or the PrecisionGoal specified.
  • For low-dimensional integrals, the default setting for PrecisionGoal is related to WorkingPrecision. For high-dimensional integrals, it is typically taken to be a fixed value, usually 2.
  • You should realize that with sufficiently pathological functions, the algorithms used by NIntegrate can give wrong answers. In most cases, you can test the answer by looking at its sensitivity to changes in the setting of options for NIntegrate.
  • Possible explicit settings for the Method option include:
"GlobalAdaptive"global adaptive integration strategy
"LocalAdaptive"local adaptive integration strategy
"DoubleExponential"double exponential quadrature
"MonteCarlo"Monte Carlo integration
"AdaptiveMonteCarlo"adaptive Monte Carlo integration
"QuasiMonteCarlo"quasi Monte Carlo integration
"AdaptiveQuasiMonteCarlo"adaptive quasi Monte Carlo integration
  • With Method->{"strategy", Method->"rule"} or Method->{"strategy", Method->{rule1, rule2, ...}} possible strategy methods include:
"GlobalAdaptive"subdivide based on global error estimates
"LocalAdaptive"subdivide based only on local error estimates
  • Methods used as rules include:
"CartesianRule"multidimensional Cartesian product of rules
"ClenshawCurtisRule"Clenshaw-Curtis rule
"GaussKronrodRule"Gauss points with Kronrod extension
"LobattoKronrodRule"Gauss-Lobatto points with Kronrod extension
"MultidimensionalRule"multidimensional symmetric rule
"MultipanelRule"combination of 1D rules
"NewtonCotesRule"Newton-Cotes rule
"TrapezoidalRule"uniform points in one dimension
  • Additional method suboptions can be given in the form Method->{..., opts}.
  • The method suboption "SymbolicProcessing" specifies the maximum number of seconds for which to attempt performing symbolic analysis of the integrand.
  • NIntegrate first localizes the values of all variables, then evaluates f with the variables being symbolic, and then repeatedly evaluates the result numerically.
Compute a numerical integral:
Compute a multidimensional integral (with singularity at the origin):
Compute a high-dimensional integral:
Compute a numerical integral:
In[1]:=
Click for copyable input
Out[1]=
 
Compute a multidimensional integral (with singularity at the origin):
In[1]:=
Click for copyable input
Out[1]=
 
Compute a high-dimensional integral:
In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
Integration over an infinite region:
Line integral in the complex plane:
Integration over an infinite strip:
Integration over a region with functional boundaries:
Integration with complex numbers:
One-dimensional integral with singularities at both ends of the integration region:
Three-dimensional integral with singularities at two of the corners:
One-dimensional integral with a singularity inside the integration region:
Specify the location of the singularity to handle it with appropriate transformations:
Compute a highly oscillatory integral with a singularity at the origin:
Fourier integral finite range:
Fourier integral finite range:
Fourier integral infinite range:
BesselJ integral infinite range:
Piecewise oscillatory integral:
Compute a 10-dimensional integral using adaptive Monte Carlo integration:
Find the volume of the unit ball in 5 dimensions:
The AccuracyGoal option can be used to change the default absolute tolerance:
The integration process stops once the accuracy goal criterion has been exceeded:
The result with the default settings is different since the default uses only a precision criterion:
Get the number of evaluation points used in a numerical integration:
Show the evaluation points used in a numerical integration:
Integration by excluding the curves on which the integrand's denominator is zero:
The curves on which the integrand is singular:
Stop integration after a specified number of points has been exceeded:
Without enough adaptive recursion, the following gives a poor result:
Specifying a larger value for MaxRecursion gives a much better result:
Specifying the singularity locations is even more efficient:
Timing for the default multidimensional rule:
Using a higher-order multidimensional rule is faster:
NIntegrate may miss sharp peaks of integrands:
Increasing MinRecursion forces a finer subdivision of the integration region:
The number of samples used to evaluate for different relative tolerances:
The number of samples needed typically increases exponentially with the PrecisionGoal:
NIntegrate can compute integrals using higher working precision:
The PrecisionGoal used is 10 less than the WorkingPrecision:
This finds the 3^(rd) quartile of the NormalDistribution using NIntegrate and FindRoot:
This finds the 3^(rd) quartile of the NormalDistribution using Quantile:
Use Green's theorem to find the area of a parametrically defined two-dimensional region:
Find the Fourier coefficients of a periodic function on [0,1]:
Show the difference between the function and the Fourier series:
When a closed-form solution is available, Integrate can be used instead of NIntegrate:
The result of NIntegrate is close to the exact value:
NDSolve can be used instead of NIntegrate:
NIntegrate will typically give a more precise result since it uses global error control:
Approximate the tail of a sum using the Euler-Maclaurin formula:
The Euler-Maclaurin formula approximation compares well with the exact result:
The Euler-Maclaurin method of NSum uses Integrate or NIntegrate:
Find a cumulative distribution function from a probability distribution function:
CDF gives the same result:
The Residue of a function at a pole is equivalent to a contour integral:
Numerically integrate on a contour that includes the real axis from -Infinity to Infinity:
Several special functions are defined as integrals:
For high precision, using the special function is usually preferable:
For integrands with complicated variation, many levels of adaptive recursion may be required:
Specifying higher recursive subdivision levels gives a convergent result:
Since the default is to use relative tolerance, integrals that are zero may be computed slowly:
Specifying an absolute tolerance with AccuracyGoal will reduce the amount of work:
Higher-dimensional cubature-based integration to default precision may be slow:
Decreasing the PrecisionGoal speeds up the computation:
Using a quasi Monte Carlo method for the same low PrecisionGoal may be even faster:
NIntegrate automatically uses Monte Carlo integration for dimensions higher than 15:
It can be time-consuming to compute functions symbolically:
Restricting the function definition avoids symbolic evaluation:
Sampling points for a 3-dimensional integration, using a low-order method:
New in 1 | Last modified in 6
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team