d01 Chapter Contents
d01 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_1d_quad_vals (d01gac)

## 1  Purpose

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

## 2  Specification

 #include #include
 void nag_1d_quad_vals (Integer n, const double x[], const double y[], double *ans, double *er, NagError *fail)

## 3  Description

nag_1d_quad_vals (d01gac) evaluates the definite integral
 $I = ∫ x 1 x n y x dx$
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 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:     nIntegerInput
On entry: the number of points, $n$.
Constraint: ${\mathbf{n}}\ge 4$.
2:     x[n]const doubleInput
On entry: the values of the independent variable, i.e., ${x}_{1},{x}_{2},\dots ,{x}_{n}$.
Constraint: either ${x}_{1}<{x}_{2}<\cdots <{x}_{n}$ or ${x}_{1}>{x}_{2}>\cdots >{x}_{n}$.
3:     y[n]const doubleInput
On entry: the values of the dependent variable ${y}_{i}$ at the points ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
4:     ansdouble *Output
On exit: the estimate of the integral.
5:     erdouble *Output
On exit: an estimate of the uncertainty in ans.
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

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.
NE_INT_ARG_LT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 4$.
NE_NOT_STRICTLY_DECREASING
The sequence x is not strictly decreasing: ${\mathbf{x}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
NE_NOT_STRICTLY_INCREASING
The sequence x is not strictly increasing: ${\mathbf{x}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
The sequence x has first two points equal: ${\mathbf{x}}\left[0\right]=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[1\right]=〈\mathit{\text{value}}〉$.

## 7  Accuracy

No accuracy level is specified before calling nag_1d_quad_vals (d01gac) but on return $\left|{\mathbf{er}}\right|$ is an approximation to, but not necessarily a bound for, $\left|I-{\mathbf{ans}}\right|$. If on exit fail is not equal to NE_NOERROR, both ans and er are returned as zero.

The time taken by nag_1d_quad_vals (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.

## 9  Example

This example evaluates the integral
 $∫ 0 1 4 1 + x 2 dx = π$
reading in the function values at 21 unequally-spaced points.

### 9.1  Program Text

Program Text (d01gace.c)

### 9.2  Program Data

Program Data (d01gace.d)

### 9.3  Program Results

Program Results (d01gace.r)