MATLAB Guide

Quadrature is a synonym for numerical integration, the approximation of definite integrals ? b a f(x) dx. MATLAB has two main functions for quadrature, quad and quadl. Both require a and b to be finite and the integrand to have no singularities on [ a,b]. For infinite integrals and integrals with singularities a variety of approaches can be used in order to produce an integral that can be handled by quad and quadl: these include change of variable, integration by parts, and analytic treatment of the integral over part of the range. See numerical analysis textbooks for details, for example, [5, Sec. 5.6], [11, Sec. 7.4.3], and [70, Sec. 5.4].
The basic usage is q = quad(fun,a,b,tol) (similarly, for quadl), where fun specifies the function to be integrated. The function fun must accept a vector argument and return a vector of function values. The argument tol is an absolute error tolerance, which defaults to a small multiple of eps times an estimate of the integral. Given the function
function f = fxlog(x) f = x.*log(x);
we type
<a name="307"></a><a name="page146"></a> <span class="unicode">?</span> quad(@fxlog,2,4) ans = 6.7041
to obtain an approximation to ? 4 2 x log xdx. Note the use of array multiplication ( *) in fxlog to make the function work for vectors.
The number of (scalar) function evaluations is returned in...