D01GAF (PDF version)
D01 Chapter Contents
D01 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

D01GAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

D01GAF integrates a function which is specified numerically at four or more points, over the whole of its specified range, using third-order finite difference formulae with error estimates, according to a method due to Gill and Miller (1972).

2  Specification

SUBROUTINE D01GAF ( X, Y, N, ANS, ER, IFAIL)
INTEGER  N, IFAIL
REAL (KIND=nag_wp)  X(N), Y(N), ANS, ER

3  Description

D01GAF evaluates the definite integral
I = x1 xn yx dx ,
where the function y is specified at the n-points x1,x2,,xn, which should be all distinct, and in either ascending or descending order. The integral between successive points is calculated by a four-point finite difference formula centred on the interval concerned, except in the case of the first and last intervals, where four-point 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).

4  References

Gill P E and Miller G F (1972) An algorithm for the integration of unequally spaced data Comput. J. 15 80–83

5  Parameters

1:     X(N) – REAL (KIND=nag_wp) arrayInput
On entry: the values of the independent variable, i.e., the x1,x2,,xn.
Constraint: either X1<X2<<XN or X1>X2>>XN.
2:     Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the values of the dependent variable yi at the points xi, for i=1,2,,n.
3:     N – INTEGERInput
On entry: n, the number of points.
Constraint: N4.
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​ 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​ 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 -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry 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:
IFAIL=1
Indicates that fewer than four points have been supplied to D01GAF.
IFAIL=2
Values of X are neither strictly increasing nor strictly decreasing.
IFAIL=3
Two points have the same X-value.
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.

7  Accuracy

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, I-ANS. If on exit IFAIL>0, both ANS and ER are returned as zero.

8  Further Comments

The time taken by D01GAF depends on the number of points supplied, n.
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.

9  Example

This example evaluates the integral
01 4 1+x2 dx = π
reading in the function values at 21 unequally spaced points.

9.1  Program Text

Program Text (d01gafe.f90)

9.2  Program Data

Program Data (d01gafe.d)

9.3  Program Results

Program Results (d01gafe.r)


D01GAF (PDF version)
D01 Chapter Contents
D01 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012