# NAG FL Interfaced01ahf (dim1_​fin_​well)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

d01ahf computes a definite integral over a finite range to a specified relative accuracy using a method described by Patterson.

## 2Specification

Fortran Interface
 Function d01ahf ( a, b, epsr, npts, f,
 Real (Kind=nag_wp) :: d01ahf Integer, Intent (In) :: nlimit Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: npts Real (Kind=nag_wp), External :: f Real (Kind=nag_wp), Intent (In) :: a, b, epsr Real (Kind=nag_wp), Intent (Out) :: relerr
#include <nag.h>
 double d01ahf_ (const double *a, const double *b, const double *epsr, Integer *npts, double *relerr, double (NAG_CALL *f)(const double *x),const Integer *nlimit, Integer *ifail)
The routine may be called by the names d01ahf or nagf_quad_dim1_fin_well.

## 3Description

d01ahf computes a definite integral of the form
 $∫abf(x)dx.$
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 sub-intervals (not always equal). The basic family is then applied to the first sub-interval. If the required accuracy is not obtained, the interval is stored for future examination (see ${\mathbf{ifail}}={\mathbf{2}}$) and the second sub-interval is examined. Should the basic family again be unsuccessful, then the sub-interval 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 sub-intervals placed in store are examined.
A large number of refinements are incorporated to improve the performance. Some of these are:
1. (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.
2. (b)The $\epsilon$-algorithm is applied to the basic results in an attempt to increase the convergence rate. See Wynn (1956).
3. (c)An attempt is made to detect sharp end point peaks and singularities in each sub-interval and to apply appropriate transformations to smooth the integrand. This consideration is also used to select interval sizes in the subdivision process.
4. (d)The relative accuracy sought in each sub-interval is adjusted in accordance with its likely contribution to the total integral.
5. (e)Random transformations of the integrand are applied to improve reliability in some instances.

## 4References

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

## 5Arguments

1: $\mathbf{a}$Real (Kind=nag_wp) Input
On entry: $a$, the lower limit of integration.
2: $\mathbf{b}$Real (Kind=nag_wp) Input
On entry: $b$, the upper limit of integration. It is not necessary that $a.
3: $\mathbf{epsr}$Real (Kind=nag_wp) Input
On entry: the relative accuracy required.
Constraint: ${\mathbf{epsr}}>0.0$.
4: $\mathbf{npts}$Integer Output
On exit: the number of function evaluations used in the calculation of the integral.
5: $\mathbf{relerr}$Real (Kind=nag_wp) Output
On exit: a rough estimate of the relative error achieved.
6: $\mathbf{f}$real (Kind=nag_wp) Function, supplied by the user. External Procedure
f must return the value of the integrand $f$ at a given point.
The specification of f is:
Fortran Interface
 Function f ( x)
 Real (Kind=nag_wp) :: f Real (Kind=nag_wp), Intent (In) :: x
 double f (const double *x)
1: $\mathbf{x}$Real (Kind=nag_wp) Input
On entry: the point at which the integrand $f$ must be evaluated.
f must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d01ahf is called. Arguments denoted as Input must not be changed by this procedure.
Note: f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d01ahf. If your code inadvertently does return any NaNs or infinities, d01ahf is likely to produce unexpected results.
7: $\mathbf{nlimit}$Integer Input
On entry: a limit to the number of function evaluations. If ${\mathbf{nlimit}}\le 0$, the routine uses a default limit of $10000$.
8: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $-1$ is recommended since useful values can be provided in some output arguments even when ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
Note: in some cases d01ahf may return useful information.
${\mathbf{ifail}}=1$
Integral has failed to converge to requested accuracy. It may be worthwhile to try increasing nlimit. A result may be obtained by continuing without further subdivision, but this is likely to be inaccurate.
${\mathbf{ifail}}=2$
Too many unsuccessful levels of subdivision. A result may be obtained by continuing without further subdivision, but this is likely to be inaccurate.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{epsr}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{epsr}}>0.0$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

The relative accuracy required is specified by you in the variable epsr. The routine 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 by-product of the computation and is not used to effect the termination of the routine. The outcome of the integration must be judged by the value of ifail.

## 8Parallelism and Performance

d01ahf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The time taken by d01ahf depends on the complexity of the integrand and the accuracy required.

## 10Example

This example evaluates the integral to a requested relative accuracy of ${10}^{-5}$
 $∫0141+x2 dx=π.$

### 10.1Program Text

Program Text (d01ahfe.f90)

### 10.2Program Data

Program Data (d01ahfe.d)

### 10.3Program Results

Program Results (d01ahfe.r)