hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_quad_1d_data (d01ga)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_quad_1d_data (d01ga) 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).

Syntax

[ans, er, ifail] = d01ga(x, y, 'n', n)
[ans, er, ifail] = nag_quad_1d_data(x, y, 'n', n)

Description

nag_quad_1d_data (d01ga) 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).

References

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

Parameters

Compulsory Input Parameters

1:     xn – double array
The values of the independent variable, i.e., the x1,x2,,xn.
Constraint: either x1<x2<<xn or x1>x2>>xn.
2:     yn – double array
The values of the dependent variable yi at the points xi, for i=1,2,,n.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
n, the number of points.
Constraint: n4.

Output Parameters

1:     ans – double scalar
The estimated value of the integral.
2:     er – double scalar
An estimate of the uncertainty in ans.
3:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
Indicates that fewer than four points have been supplied to nag_quad_1d_data (d01ga).
   ifail=2
Values of x are neither strictly increasing nor strictly decreasing.
   ifail=3
Two points have the same X-value.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.
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.

Accuracy

No accuracy level is specified by you before calling nag_quad_1d_data (d01ga) 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.

Further Comments

The time taken by nag_quad_1d_data (d01ga) 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.

Example

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


fprintf('d01ga example results\n\n');

x = [0:0.04:1];
y = 4./(1+x.^2);

[ans, err, ifail] = d01ga(x, y);
fprintf('Integral =  %9.6f     Estimated error = %9.2e\n',ans,err);


d01ga example results

Integral =   3.141593     Estimated error = -3.19e-07

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015