## Purpose

Numerical evaluation of integrals.

## Synopsis

````a = quad('function',a,b)`
`a = quad('function',a,b,tol)`
`a = quad('function',a,b,tol,trace)`
`a = quad8('function',a,b)`
`a = quad8('function',a,b,tol)`
`a = quad8('function',a,b,tol,trace)`
```

## Description

Quadrature is a numerical method of finding the area under the graph of a function, that is, computing a definite integral.

`quad` and `quad8` implement two different quadrature algorithms. `quad` implements a low order method using an adaptive recursive Simpson's rule. `quad8` implements a higher order method using an adaptive recursive Newton-Cotes 8 panel rule.

`q = quad('function',a,b)` returns the result of numerically integrating the function `fun(x)` between the limits `a` and `b`. The function `function` must return a vector of output values when given a vector of input values.

`q = quad('function',a,b,tol)` iterates until the relative error is less than `tol`. The default value for `tol` is 1e-3.

If the final argument `trace` is nonzero, `quad` plots a graph showing the progress of the integration.

`quad8` has the same calling sequence as `quad`.

## Examples

Integrate the sine function from 0 to ¶:

````a = quad('sin',0,pi)`
`          `
`a =`
`    2.0000`
```

## Algorithm

`quad` uses an adaptive recursive Simpson's rule. `quad8` uses an adaptive recursive Newton-Cotes 8 panel rule. `quad8` is better than `quad` at handling functions with soft singularities:

## Diagnostics

`quad` and `quad8` have recursion level limits of 10 to prevent infinite recursion for a singular integral. Reaching this limit in one of the integration intervals produces the warning message:

````Recursion level limit reached in quad.` `Singularity likely.`
```
The computation continues using the best value available in that interval.

## Limitations

Neither `quad` nor `quad8` is set up to handle integrable singularities:

If you need to evaluate an integral with such a singularity, recast the problem by transforming the problem into one in which you can explicitly evaluate the integrable singularities and let `quad` or `quad8` take care of the remainder.

````quaddemo` demonstration program