# Adaptive Quadrature Algorithm For Numerical Integration

by admin in Math, Statistics, and Optimization , MATLAB Family , Numerical Integration on June 18, 2019The composite quadrature rules necessitate the use of equally spaced points. Typically, a small step size h was used uniformly across the entire interval of integration to ensure the overall accuracy. This does not take into account that some portions of the curve may have large functional variations that require more attention than other portions of the curve. It is useful to introduce a method that adjusts the step size to be smaller over portions of the curve where a larger functional variation occurs. This technique is called adaptive quadrature. The method is based on Simpson’s rule.

Explanation Link: https://bit.ly/2IUkFSH

### Example On Using This Code

#### Input

% Find the integral of y = sin(x) from 0 to pi. f = @(x) sin(x); % function we interest to integrate xi = 0; % lower limit xf = pi; % upper limit n = 100; % maximum no. of levels eps = eps; % tolerance

#### Output

The approximate integral is: 2.00000000

### General Scheme

Adaptive quadrature follows the general scheme

1.procedureintegrate ( f, a, b, tau) 2. 3. 4.ifthen5. m = (a + b) / 2 6. Q = integrate(f, a, m, tau/2) + integrate(f, a, m, tau/2) 7.endif8.returnQ

An approximation Q to the integral of f(x) over the interval [a,b] is computed (line 2), as well as an error estimate **epsilon** (line 3). If the estimated error is larger than the required tolerance **tau** (line 4), the interval is subdivided (line 5) and the quadrature is applied on both halves separately (line 6). Either the initial estimate or the sum of the recursively computed halves is returned (line 7).

The important components are the quadrature rule itself

the error estimator

and the logic for deciding which interval to subdivide, and when to terminate. There are several variants of this scheme. The most common will be discussed later.

### Basic Rules

The quadrature rules generally have the form

where the nodes x_{i} and weights w_{i} are generally precomputed. In the simplest case, Newton–Cotes formulas of even degree are used, where the nodes x_{i} are evenly spaced in the interval:

.

When such rules are used, the points at which f(x) has been evaluated can be re-used upon recursion:

A similar strategy is used with Clenshaw–Curtis quadrature, where the nodes are chosen as

.

Or, when Fejér quadrature is used,

.

Other quadrature rules, such as Gaussian quadrature or Gauss-Kronrod quadrature, may also be used.

An algorithm may elect to use different quadrature methods on different subintervals, for example using a high-order method only where the integrand is smooth.

### Error Estimation

Some quadrature algorithms generate a sequence of results which should approach the correct value. Otherwise one can use a “null rule” which has the form of the above quadrature rule, but whose value would be zero for a simple integrand (for example, if the integrand were a polynomial of the appropriate degree).

### Subdivision Logic

“Local” adaptive quadrature makes the acceptable error for a given interval proportional to the length of that interval. This criterion can be difficult to satisfy if the integrands are badly behaved at only a few points, for example with a few step discontinuities. Alternatively, one could require only that the sum of the errors on each of the subintervals be less than the user’s requirement. This would be “global” adaptive quadrature. Global adaptive quadrature can be more efficient (using fewer evaluations of the integrand) but is generally more complex to program and may require more working space to record information on the current set of intervals.

### References

- McKeeman, William (December 1962). Gotlieb, Calvin (ed.). “Algorithm 145: Adaptive numerical integration by Simpson’s rule”.
*Communications of the ACM*(Periodical). New York: ACM.**5**(12): 604–605. doi:10.1145/355580.369102. eISSN 1557-7317. ISSN 0001-0782. OCLC 1011805770. - John R. Rice. A Metalgorithm for Adaptive Quadrature. Journal of the ACM 22(1) pp 61-82 (January 1975).
- Press, WH; Teukolsky, SA; Vetterling, WT; Flannery, BP (2007), “Section 4.7. Adaptive Quadrature”,
*Numerical Recipes: The Art of Scientific Computing*(3rd ed.), New York: Cambridge University Press, ISBN 978-0-521-88068-8

Share Now!