Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Numerically evaluate double integral

`q = integral2(fun,xmin,xmax,ymin,ymax)`

`q = integral2(fun,xmin,xmax,ymin,ymax,Name,Value)`

The

`integral2`

function attempts to satisfy:whereabs(q - Q) <= max(AbsTol,RelTol*abs(q))

`q`

is the computed value of the integral and`Q`

is the (unknown) exact value. The absolute and relative tolerances provide a way of trading off accuracy and computation time. Usually, the relative tolerance determines the accuracy of the integration. However if`abs(q)`

is sufficiently small, the absolute tolerance determines the accuracy of the integration. You should generally specify both absolute and relative tolerances together.The

`'iterated'`

method can be more effective when your function has discontinuities within the integration region. However, the best performance and accuracy occurs when you split the integral at the points of discontinuity and sum the results of multiple integrations.When integrating over nonrectangular regions, the best performance and accuracy occurs when

`ymin`

,`ymax`

, (or both) are function handles. Avoid setting integrand function values to zero to integrate over a nonrectangular region. If you must do this, specify`'iterated'`

method.Use the

`'iterated'`

method when`ymin`

,`ymax`

, (or both) are unbounded functions.When paramaterizing anonymous functions, be aware that parameter values persist for the life of the function handle. For example, the function

`fun = @(x,y) x + y + a`

uses the value of`a`

at the time`fun`

was created. If you later decide to change the value of`a`

, you must redefine the anonymous function with the new value.If you are specifying single-precision limits of integration, or if

`fun`

returns single-precision results, you might need to specify larger absolute and relative error tolerances.

[1] L.F. Shampine “*Vectorized
Adaptive Quadrature in MATLAB ^{®}*,”

[2] L.F. Shampine, "*MATLAB Program
for Quadrature in 2D.*" *Applied Mathematics
and Computation.* Vol. 202, Issue 1, 2008, pp. 266–274.