NAG CL Interface
d01gac (dim1_​data)

1 Purpose

d01gac 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

#include <nag.h>
void  d01gac (Integer n, const double x[], const double y[], double *ans, double *er, NagError *fail)
The function may be called by the names: d01gac, nag_quad_dim1_data or nag_1d_quad_vals.

3 Description

d01gac 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 function 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 Arguments

1: n Integer Input
On entry: n, the number of points.
Constraint: n4.
2: x[n] const double Input
On entry: the values of the independent variable, i.e., the x1,x2,,xn.
Constraint: either x[0]<x[1]<<x[n-1] or x[0]>x[1]>>x[n-1].
3: y[n] const double Input
On entry: the values of the dependent variable yi at the points xi, for i=1,2,,n.
4: ans double * Output
On exit: the estimated value of the integral.
5: er double * Output
On exit: an estimate of the uncertainty in ans.
6: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, n=value.
Constraint: n4.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_STRICTLY_DECREASING
On entry, x[value]=value and x[value]=value.
Constraint: x[0]>x[1]>>x[n-1].
NE_NOT_STRICTLY_INCREASING
On entry, x[value]=value and x[value]=value.
Constraint: x[0]<x[1]<<x[n-1].
NE_QUAD_FIRST_TWO_PTS_EQL
The sequence x has first two points equal: x[0]=value and x[1]=value.

7 Accuracy

No accuracy level is specified by you before calling d01gac but on return the absolute value of er is an approximation to, but not necessarily a bound for, I-ans. If on exit fail.code= NE_INT, NE_NOT_STRICTLY_DECREASING, NE_NOT_STRICTLY_INCREASING or NE_QUAD_FIRST_TWO_PTS_EQL, both ans and er are returned as zero.

8 Parallelism and Performance

d01gac is not threaded in any implementation.

9 Further Comments

The time taken by d01gac 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 function.

10 Example

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

10.1 Program Text

Program Text (d01gace.c)

10.2 Program Data

Program Data (d01gace.d)

10.3 Program Results

Program Results (d01gace.r)