This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Numerical Integration

N[Integrate[expr,{x,xmin,xmax}]]try to perform an integral exactly, then find numerical approximations to the parts that remain
NIntegrate[expr,{x,xmin,xmax}]find a numerical approximation to an integral
multidimensional numerical integral
do a numerical integral along a line, starting at xmin, going through the points xi, and ending at xmax

Numerical integration functions.

This finds a numerical approximation to the integral .
Click for copyable input
Here is the numerical value of the double integral .
Click for copyable input
An important feature of NIntegrate is its ability to deal with functions that "blow up" at known points. NIntegrate automatically checks for such problems at the end points of the integration region.
The function blows up at x=0, but NIntegrate still succeeds in getting the correct value for the integral.
Click for copyable input
Mathematica can find the integral of exactly.
Click for copyable input
NIntegrate detects that the singularity in 1/x at x=0 is not integrable.
Click for copyable input
NIntegrate does not automatically look for singularities except at the end points of your integration region. When other singularities are present, NIntegrate may not give you the right answer for the integral. Nevertheless, in following its adaptive procedure, NIntegrate will often detect the presence of potentially singular behavior, and will warn you about it.
NIntegrate warns you of a possible problem due to the singularity in the middle of the integration region. The final result is numerically quite close to the correct answer.
Click for copyable input
If you know that your integrand has singularities at particular points, you can explicitly tell NIntegrate to deal with them. NIntegrate[expr, {x, xmin, x1, x2, ..., xmax}] integrates expr from xmin to xmax, looking for possible singularities at each of the intermediate points xi.
This gives the same integral, but now explicitly deals with the singularity at x=0.
Click for copyable input
You can also use the list of intermediate points xi in NIntegrate to specify an integration contour to follow in the complex plane. The contour is taken to consist of a sequence of line segments, starting at xmin, going through each of the xi, and ending at xmax.
This integrates 1/x around a closed contour in the complex plane, going from -1, through the points -i, 1 and i, then back to -1.
Click for copyable input
The integral gives 2i, as expected from Cauchy's Theorem.
Click for copyable input
option name
default value
MinRecursion0minimum number of recursions for the integration method
MaxRecursionAutomaticmaximum number of recursions for the integration method
MaxPointsAutomaticmaximum total number of times to sample the integrand

Special options for NIntegrate.

When NIntegrate tries to evaluate a numerical integral, it samples the integrand at a sequence of points. If it finds that the integrand changes rapidly in a particular region, then it recursively takes more sample points in that region. The parameters MinRecursion and MaxRecursion specify the minimum and maximum number of recursions to use. Increasing the value of MinRecursion guarantees that NIntegrate will use a larger number of sample points. MaxPoints and MaxRecursion limit the number of sample points which NIntegrate will ever try to use. Increasing MinRecursion or MaxRecursion will make NIntegrate work more slowly.
With the default settings for all options, NIntegrate misses the peak in exp (- (x-1)2) near x=1, and gives the wrong answer for the integral.
Click for copyable input
With the option MinRecursion->3, NIntegrate samples enough points that it notices the peak around x=1. With the default setting of MaxRecursion, however, NIntegrate cannot use enough sample points to be able to expect an accurate answer.
Click for copyable input
With this setting of MaxRecursion, NIntegrate can get an accurate answer for the integral.
Click for copyable input
Another way to solve the problem is to make NIntegrate break the integration region into several pieces, with a small piece that explicitly covers the neighborhood of the peak.
Click for copyable input
For integrals in many dimensions, it can take a long time for NIntegrate to get a precise answer. However, by setting the option MaxPoints, you can tell NIntegrate to give you just a rough estimate, sampling the integrand only a limited number of times.
Here is a way to get a rough estimate for an integral that takes a long time to compute.
Click for copyable input