Numerically evaluate integral, adaptive Lobatto quadrature

`quadl`

will be removed in a future release.
Use `integral`

instead.

`q = quadl(fun,a,b)`

q = quadl(fun,a,b,tol)

quadl(fun,a,b,tol,trace)

[q,fcnt] = quadl(...)

`q = quadl(fun,a,b)`

approximates
the integral of function `fun`

from `a`

to `b`

,
to within an error of 10^{-6} using recursive
adaptive Lobatto quadrature. `fun`

is a function
handle. It accepts a vector `x`

and returns a vector `y`

,
the function `fun`

evaluated at each element of `x`

.
Limits `a`

and `b`

must be finite.

Parameterizing Functions explains how to provide additional
parameters to the function `fun`

, if necessary.

`q = quadl(fun,a,b,tol)`

uses
an absolute error tolerance of `tol`

instead of the
default, which is `1.0e-6`

. Larger values of `tol`

result
in fewer function evaluations and faster computation, but less accurate
results.

`quadl(fun,a,b,tol,trace)`

with
non-zero `trace`

shows the values of `[fcnt a b-a q]`

during
the recursion.

`[q,fcnt] = quadl(...)`

returns
the number of function evaluations.

Use array operators `.*`

, `./`

and `.^`

in
the definition of `fun`

so that it can be evaluated
with a vector argument.

The function `quad`

might be more efficient
with low accuracies or nonsmooth integrands.

The list below contains information to help you determine which
quadrature function in MATLAB^{®} to use:

The

`quad`

function might be most efficient for low accuracies with nonsmooth integrands.The

`quadl`

function might be more efficient than`quad`

at higher accuracies with smooth integrands.The

`quadgk`

function might be most efficient for high accuracies and oscillatory integrands. It supports infinite intervals and can handle moderate singularities at the endpoints. It also supports contour integration along piecewise linear paths.The

`quadv`

function vectorizes`quad`

for an array-valued`fun`

.If the interval is infinite,

`[a,Inf)`

, then for the integral of`fun(x)`

to exist,`fun(x)`

must decay as`x`

approaches infinity, and`quadgk`

requires it to decay rapidly. Special methods should be used for oscillatory functions on infinite intervals, but`quadgk`

can be used if`fun(x)`

decays fast enough.The

`quadgk`

function will integrate functions that are singular at finite endpoints if the singularities are not too strong. For example, it will integrate functions that behave at an endpoint`c`

like`log|x-c|`

or`|x-c|`

for^{p}`p >= -1/2`

. If the function is singular at points inside`(a,b)`

, write the integral as a sum of integrals over subintervals with the singular points as endpoints, compute them with`quadgk`

, and add the results.

Pass the function handle, `@myfun`

, to `quadl`

:

Q = quadl(@myfun,0,2);

where the function `myfun.m`

is:

function y = myfun(x) y = 1./(x.^3-2*x-5);

Pass anonymous function handle `F`

to `quadl`

:

F = @(x) 1./(x.^3-2*x-5); Q = quadl(F,0,2);

`quadl`

might issue one of the following
warnings:

`'Minimum step size reached'`

indicates that
the recursive interval subdivision has produced a subinterval whose
length is on the order of roundoff error in the length of the original
interval. A nonintegrable singularity is possible.

`'Maximum function count exceeded'`

indicates
that the integrand has been evaluated more than 10,000 times. A nonintegrable
singularity is likely.

`'Infinite or Not-a-Number function value encountered'`

indicates
a floating point overflow or division by zero during the evaluation
of the integrand in the interior of the interval.

[1] Gander, W. and W. Gautschi, "Adaptive
Quadrature – Revisited," BIT, Vol. 40,
2000, pp. 84-101. This document is also available at `http://www.inf.ethz.ch/personal/gander`

.

`dblquad`

| `function_handle`

| `integral`

| `integral2`

| `integral3`

| `quad`

| `quad2d`

| `quadgk`

| `triplequad`

Was this topic helpful?