PDF version (NAG web site
, 64bit version, 64bit version)
NAG Toolbox: nag_quad_1d_fin_well (d01ah)
Purpose
nag_quad_1d_fin_well (d01ah) computes a definite integral over a finite range to a specified relative accuracy using a method described by Patterson.
Syntax
Description
nag_quad_1d_fin_well (d01ah) computes a definite integral of the form
The method uses as its basis a family of interlacing high precision rules (see
Patterson (1968)) using
$1$,
$3$,
$7$,
$15$,
$31$,
$63$,
$127$ and
$255$ nodes. Initially the family is applied in sequence to the integrand. When two successive rules differ relatively by less than the required relative accuracy, the last rule used is taken as the value of the integral and the operation is regarded as successful. If all rules in the family have been applied unsuccessfully, subdivision is invoked. The subdivision strategy is as follows. The interval under scrutiny is divided into two subintervals (not always equal). The basic family is then applied to the first subinterval. If the required accuracy is not obtained, the interval is stored for future examination (see
${\mathbf{ifail}}={\mathbf{2}}$) and the second subinterval is examined. Should the basic family again be unsuccessful, then the subinterval is further subdivided and the whole process repeated. Successful integrations are accumulated as the partial value of the integral. When all possible successful integrations have been completed, those previously unsuccessful subintervals placed in store are examined.
A large number of refinements are incorporated to improve the performance. Some of these are:
(a) 
The rate of convergence of the basic family is monitored and used to make a decision to abort and subdivide before the full sequence has been applied. 
(b) 
The $\epsilon $algorithm is applied to the basic results in an attempt to increase the convergence rate. See Wynn (1956). 
(c) 
An attempt is made to detect sharp end point peaks and singularities in each subinterval and to apply appropriate transformations to smooth the integrand. This consideration is also used to select interval sizes in the subdivision process. 
(d) 
The relative accuracy sought in each subinterval is adjusted in accordance with its likely contribution to the total integral. 
(e) 
Random transformations of the integrand are applied to improve reliability in some instances. 
References
Patterson T N L (1968) The Optimum addition of points to quadrature formulae Math. Comput. 22 847–856
Wynn P (1956) On a device for computing the ${e}_{m}\left({S}_{n}\right)$ transformation Math. Tables Aids Comput. 10 91–96
Parameters
Compulsory Input Parameters
 1:
$\mathrm{a}$ – double scalar

$a$, the lower limit of integration.
 2:
$\mathrm{b}$ – double scalar

$b$, the upper limit of integration. It is not necessary that $a<b$.
 3:
$\mathrm{epsr}$ – double scalar

The relative accuracy required.
Constraint:
${\mathbf{epsr}}>0.0$.
 4:
$\mathrm{f}$ – function handle or string containing name of mfile

f must return the value of the integrand
$f$ at a given point.
[result] = f(x)
Input Parameters
 1:
$\mathrm{x}$ – double scalar

The point at which the integrand $f$ must be evaluated.
Output Parameters
 1:
$\mathrm{result}$ – double scalar

The value of the integrand at
x
 5:
$\mathrm{nlimit}$ – int64int32nag_int scalar

A limit to the number of function evaluations. If ${\mathbf{nlimit}}\le 0$, the function uses a default limit of $10000$.
Optional Input Parameters
None.
Output Parameters
 1:
$\mathrm{result}$ – double scalar

The value of the definite interval.
 2:
$\mathrm{npts}$ – int64int32nag_int scalar

The number of function evaluations used in the calculation of the integral.
 3:
$\mathrm{relerr}$ – double scalar

A rough estimate of the relative error achieved.
 4:
$\mathrm{ifail}$ – int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Note: nag_quad_1d_fin_well (d01ah) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
 W ${\mathbf{ifail}}=1$

The integral has not converged to the accuracy requested. It may be worthwhile to try increasing
nlimit.
 W ${\mathbf{ifail}}=2$

Too many unsuccessful levels of subdivision have been invoked.
 ${\mathbf{ifail}}=3$

On entry,  ${\mathbf{epsr}}\le 0.0$. 
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
 ${\mathbf{ifail}}=399$
Your licence key may have expired or may not have been installed correctly.
 ${\mathbf{ifail}}=999$
Dynamic memory allocation failed.
When ${\mathbf{ifail}}={\mathbf{1}}$ or ${\mathbf{2}}$ a result may be obtained by continuing without further subdivision, but this is likely to be inaccurate.
Accuracy
The relative accuracy required is specified by you in the variable
epsr. The function will terminate whenever the relative accuracy specified by
epsr is judged to have been reached.
If on exit, ${\mathbf{ifail}}={\mathbf{0}}$, then it is most likely that the result is correct to the specified accuracy. If, on exit, ${\mathbf{ifail}}={\mathbf{1}}$ or ${\mathbf{2}}$, then it is likely that the specified accuracy has not been reached.
relerr is a rough estimate of the relative error achieved. It is a byproduct of the computation and is not used to effect the termination of the function. The outcome of the integration must be judged by the value of
ifail.
Further Comments
The time taken by nag_quad_1d_fin_well (d01ah) depends on the complexity of the integrand and the accuracy required.
Example
This example evaluates the integral to a requested relative accuracy of
${10}^{5}$
Open in the MATLAB editor:
d01ah_example
function d01ah_example
fprintf('d01ah example results\n\n');
a = 0;
b = 1;
epsr = 1e5;
nlimit = int64(0);
[result, npts, relerr, ifail] = d01ah(...
a, b, epsr, @fcn, nlimit);
fprintf('Integral = %9.5f\n\n', result);
fprintf('Estimated relative error = %10.2e\n\n', relerr);
fprintf('Number of function evaluations = %4d\n', npts);
function f = fcn(x)
f = 4/(1+x^2);
d01ah example results
Integral = 3.14159
Estimated relative error = 5.85e09
Number of function evaluations = 15
PDF version (NAG web site
, 64bit version, 64bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015