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

Documentation / Mathematica / Add-ons & Links / Standard Packages / NumericalMath /


The Mathematica function NIntegrate uses algorithms that assume that the integrand is smooth to at least several orders. InterpolatingFunction objects typically do not satisfy this assumption; they are continuous, but only piecewise smooth. The algorithms used by NIntegrate converge very slowly when applied to InterpolatingFunction objects, especially in several dimensions. NIntegrate allows the domain of integration to be broken up into several pieces and the integral evaluated over each piece. If the pieces of the domain correspond to the pieces over which the InterpolatingFunction is smooth, NIntegrate will converge much more rapidly. NIntegrateInterpolatingFunction automatically breaks up the domain of integration.

Numerical approximations to integrals with InterpolatingFunction objects in the integrand.

NIntegrateInterpolatingFunction uses the function NIntegrate, but it breaks up the domain into sections where the InterpolatingFunction object is smooth.

This loads the package.

In[1]:= <<NumericalMath`NIntegrateInterpolatingFunct`

This creates an InterpolatingFunction object approximating an oscillatory function in two dimensions.

In[2]:= sin = Interpolation[
Flatten[Table[{x, y, Sin[x y]},
{x, 0, 4, .5}, {y, 0, 4, 0.5}],


This list gives the time used to evaluate the integral plus the result of the integral.

In[3]:= NIntegrateInterpolatingFunction[sin[y^2, x^2]^2,
{x, 0, 2}, {y, 0, 2}] // Timing


NIntegrate produces almost exactly the same result, but takes much longer because the convergence is poor if the domain is not properly broken up.

In[4]:= NIntegrate[sin[y^2, x^2]^2,
{x, 0, 2}, {y, 0, 2}] // Timing


If you simply need to find the integral of an InterpolatingFunction object (as opposed to a function of one), it is better to use Integrate because this gives you the result which is exact for the polynomial approximation used in the InterpolatingFunction object.