D01GAF integrates a function which is specified numerically at four or more points, over the whole of its specified range, using thirdorder finite difference formulae with error estimates, according to a method due to
Gill and Miller (1972).
D01GAF evaluates the definite integral
where the function
$y$ is specified at the
$n$points
${x}_{1},{x}_{2},\dots ,{x}_{n}$, which should be all distinct, and in either ascending or descending order. The integral between successive points is calculated by a fourpoint finite difference formula centred on the interval concerned, except in the case of the first and last intervals, where fourpoint forward and backward difference formulae respectively are employed. If
$n$ is less than
$4$, the routine fails. An approximation to the truncation error is integrated and added to the result. It is also returned separately to give an estimate of the uncertainty in the result. The method is due to
Gill and Miller (1972).
Gill P E and Miller G F (1972) An algorithm for the integration of unequally spaced data Comput. J. 15 80–83
 1: X(N) – REAL (KIND=nag_wp) arrayInput
On entry: the values of the independent variable, i.e., the ${x}_{1},{x}_{2},\dots ,{x}_{n}$.
Constraint:
either ${\mathbf{X}}\left(1\right)<{\mathbf{X}}\left(2\right)<\cdots <{\mathbf{X}}\left({\mathbf{N}}\right)$ or ${\mathbf{X}}\left(1\right)>{\mathbf{X}}\left(2\right)>\cdots >{\mathbf{X}}\left({\mathbf{N}}\right)$.
 2: Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the values of the dependent variable
${y}_{\mathit{i}}$ at the points ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
 3: N – INTEGERInput
On entry: $n$, the number of points.
Constraint:
${\mathbf{N}}\ge 4$.
 4: ANS – REAL (KIND=nag_wp)Output
On exit: the estimated value of the integral.
 5: ER – REAL (KIND=nag_wp)Output
On exit: an estimate of the uncertainty in
ANS.
 6: IFAIL – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
$0$.
When the value $\mathbf{1}\text{ 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).
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
No error is reported arising from the relative magnitudes of
ANS and
ER on return, due to the difficulty when the true answer is zero.
No accuracy level is specified by you before calling D01GAF but on return the absolute value of
ER is an approximation to, but not necessarily a bound for,
$\leftI{\mathbf{ANS}}\right$. If on exit
${\mathbf{IFAIL}}>{\mathbf{0}}$, both
ANS and
ER are returned as zero.
In their paper,
Gill and Miller (1972) do not add the quantity
ER to
ANS before return. However, extensive tests have shown that a dramatic reduction in the error often results from such addition. In other cases, it does not make an improvement, but these tend to be cases of low accuracy in which the modified answer is not significantly inferior to the unmodified one. You have the option of recovering the Gill–Miller answer by subtracting
ER from
ANS on return from the routine.
This example evaluates the integral
reading in the function values at
$21$ unequally spaced points.