# intquad3#

## Purpose#

Integrates a specified function using Gauss-Legendre quadrature. A suite of upper and lower bounds may be calculated in one procedure call.

## Format#

y = intquad3(&f, xlims, ylims, zlims, ...)#
Parameters:
• &f (scalar) – pointer to the procedure containing the function to be integrated. f is a function of $$(x, y, z)$$.

• xlims (2x1 or 2xN matrix) – the limits of x.

• ylims (2x1 or 2xN matrix) – the limits of y.

• zlims (2x1 or 2xN matrix) – the limits of z.

• ... (any) – Optional. A variable number of extra scalar arguments to pass to the user function. These arguments will be passed to the user function untouched.

Returns:

y (Nx1 vector) – of the estimated integral(s) of $$f(x,y,z)$$ evaluated between the limits given by xl, yl, and zl.

## Global Input#

_intord#

scalar, the order of the integration. The larger _intord, the more precise the final result will be. _intord may be set to 2, 3, 4, 6, 8, 12, 16, 20, 24, 32, 40.

Default = 12.

## Examples#

### Basic example#

// Define function to integrate
proc f(x, y, z);
retp(sqrt(x.^2 +  y.^2  +  z.^2));
endp;

// Define limits of integration
xlims = { 1, 0 };
ylims = { 1, 0 };
zlims = { 3, 0 };

// Calculate integral
ans = intquad3(&f, xlims, ylims, zlims);


After the code above, ans should equal:

5.2994691


### Passing extra arguments#

// Define function to integrate which takes an additional argument
proc f(x, y, z, a);
retp(sqrt(a .* x.^2 +  y.^2  +  z.^2));
endp;

// Define limits of integration
xlims = { 1, 0 };
ylims = { 1, 0 };
zlims = { 3, 0 };

// Define extra scalar argument
a = 3.14;

// Calculate integral, passing in extra scalar argument
ans = intquad3(&f, xlims, ylims, zlims, a);


After the code above, ans should equal:

5.8969356


### Multiple limits of integration#

// Define function to integrate
proc f(x, y, z);
retp(sqrt(x.^2 +  y.^2  +  z.^2));
endp;

// Define 3 sets of limits of integration
xlims = { 1, 0 };
ylims = { 1, 0 };
zlims = { 1 2 3,
0 0 0 };

// Calculate integrals
ans = intquad3(&f, xlims, ylims, zlims);


This will integrate the function $$f(x) = x*y*z$$ over 3 sets of limits, since zlim is defined to be a 2x3 matrix. The value of ans should be:

0.96059195
2.6692443
5.2994691


## Remarks#

The user-defined function f must return a vector of function values. intquad3() will pass to the user-defined function a vector or matrix for x, y and z and expect a vector or matrix to be returned. Use .* and ./ instead of * and /.

intquad3() will expand scalars to the appropriate size. This means that functions can be defined to return a scalar constant. If users write their functions incorrectly (using * instead of .*, for example), intquad3() may not compute the expected integral, but the integral of a constant function.

To integrate over a region which is bounded by functions, rather than just scalars, use intgrat2() or intgrat3().

integral.src

## Globals#

_intord, _intq12, _intq16, _intq2, _intq20, _intq24, _intq3, _intq32, _intq4, _intq40, _intq6, _intq8

See also