Integration
Numerical methods of approximating integrals are important in many areas of pure and applied science. For a function of a single variable, f (x), it is often the case that the antiderivative F = Ú f (x) dx is unavailable using standard techniques such as trigonometric substitutions and integration-by-parts formulas. These standard techniques become increasingly unusable when integrating multivariate functions,
f (x, y) and f (x, y, z). Numerically approximating the integral operator provides the only method of solution when the antiderivative is not explicitly available. IDL offers the following numerical methods for the integration of uni-, bi-, and trivariate functions:
- Integration of a univariate function over an open or closed interval is possible using one of several routines based on well known methods developed by Romberg and Simpson.

- The problem of integrating over a tabulated set of data { xi, yi = f (xi) } can be solved using a highly accurate 5-point Newton-Cotes formula. This method is more accurate and efficient than using interpolation or curve-fitting to find an approximate function and then integrating.
- Integration of a bivariate function over a regular or irregular region in the x-y plane is possible using an iterated Gaussian Quadrature routine.

- Integration of a trivariate function over a regular or irregular region in x-y-z space is possible using an iterated Gaussian Quadrature routine.

Note
IDL's iterated Gaussian Quadrature routines, INT_2D and INT_3D, follow the dy-dx and dz-dy-dx order of evaluation, respectively. Problems not conforming to this standard must be changed as described in the following example.
A Bivariate Function
Suppose that we wish to evaluate

The order of integration is initially described as a dx-dy region in the x-y plane. Using the diagram below, you can easily change the integration order to dy-dx.
The integral is now of the form

The new expression can be evaluated using the INT_2D function.
To use INT_2D, we must specify the function to be integrated and expressions for the upper and lower limits of integration. First, we write an IDL function for the integrand, the function f (x, y):
Next, we write a function for the limits of integration of the inner integral. Note that the limits of the outer integral are specified numerically, in vector form, while the limits of the inner integral must be specified as an IDL function even if they are constants. In this case, the function is:
Now we can use the following IDL commands to print the value of the integral expressed above. First, we define a variable AB_LIMITS containing the vector of lower and upper limits of the outer integral. Next, we call INT_2D. The first argument is the name of the IDL function that represents the integrand (FXY, in this case). The second argument is the name of the variable containing the vector of limits for the outer integral (AB_LIMITS, in this case). The third argument is the name of the IDL function defining the lower and upper limits of the inside integral (PQ_LIMITS, in this case). The fourth argument (48) refers to the number of transformation points used in the computation. As a general rule, the number of transformation points used with iterated Gaussian Quadrature should increase as the integrand becomes more oscillatory or the region of integration becomes more irregular.
IDL prints:
This is the exact solution to 9 decimal accuracy.
A Trivariate Function
Suppose that we wish to evaluate

This integral can be evaluated using the INT_3D function. As with INT_2D, we must specify the function to be integrated and expressions for the upper and lower limits of integration. Note that in this case IDL functions must be provided for the upper and lower integration limits of both inside integrals.
For the above integral, the required functions are the integrand f (x, y, z):
The limits of integration of the first inside integral:
The limits of integration of the second inside integral:
We can use the following IDL commands to determine the value of the above integral using 6, 10, 20 and 48 transformation points.
For 6 transformation points:
IDL prints:
For 10 transformation points:
IDL prints:
20 transformation points:
IDL prints:
48 transformation points:
IDL prints:
The exact solution to 6-decimal accuracy is 57.446267.
Routines for Differentiation and Integration
See Differentiation and Integration (in the functional category "Mathematics" (IDL Quick Reference)) for a brief description of IDL routines for differentiation and integration. Detailed information is available in the IDL Reference Guide.
