integral2

Numerical double integral over a rectangle or a region with variable limits.

Category: Mathematics > Numerical Integration and Differential Equations

Syntax

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

Integrates fun(x, y) over a rectangle.

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

Sets options such as 'AbsTol', 'RelTol' and 'Method'.

Description

The integrand must work on arrays, so use element-wise operators. Making ymin and ymax functions of x lets you integrate over regions bounded by curves, such as a triangle 0 <= y <= x.

The area of a region is the integral of the constant 1, but write it as @(x,y) ones(size(x)) so that the result keeps the array shape.

Input arguments

fun
Handle z = fun(x, y) that accepts arrays of the same size and returns an array of that size.
xmin, xmax
Limits of x, scalars.
ymin, ymax
Limits of y: scalars, or function handles of x for a non-rectangular region.

Output arguments

q
Approximate value of the integral.

Example

Rectangle and triangle

f = @(x, y) x.*y;
integral2(f, 0, 1, 0, 1)
integral2(f, 0, 1, 0, @(x) x)
Output
ans = 0.2500
ans = 0.1250

See also

integral integral3 dblquad quad2d