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)

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
xn
I = y(x)dx,
x1
I = x1 xn y(x) dx ,
where the function yy is specified at the nn-points x1,x2,,xnx1,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 nn is less than 44, 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:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n4n4.
The values of the independent variable, i.e., the x1,x2,,xnx1,x2,,xn.
Constraint: either x(1) < x(2) < < x(n)x1<x2<<xn or x(1) > x(2) > > x(n)x1>x2>>xn.
2:     y(n) – double array
n, the dimension of the array, must satisfy the constraint n4n4.
The values of the dependent variable yiyi at the points xixi, for i = 1,2,,ni=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.)
nn, the number of points.
Constraint: n4n4.

Input Parameters Omitted from the MATLAB Interface

None.

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 = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
Indicates that fewer than four points have been supplied to nag_quad_1d_data (d01ga).
  ifail = 2ifail=2
Values of x are neither strictly increasing nor strictly decreasing.
  ifail = 3ifail=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.

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, |Ians||I-ans|. If on exit ifail > 0ifail>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, nn.
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

function nag_quad_1d_data_example
x = [0;
     0.04;
     0.08;
     0.12;
     0.22;
     0.26;
     0.3;
     0.38;
     0.39;
     0.42;
     0.45;
     0.46;
     0.6;
     0.68;
     0.72;
     0.73;
     0.83;
     0.85;
     0.88;
     0.9;
     1];
y = [4;
     3.9936;
     3.9746;
     3.9432;
     3.8153;
     3.7467;
     3.6697;
     3.4943;
     3.4719;
     3.4002;
     3.3264;
     3.3014;
     2.9412;
     2.7352;
     2.6344;
     2.6094;
     2.3684;
     2.3222;
     2.2543;
     2.2099;
     2];
[ans, er, ifail] = nag_quad_1d_data(x, y)
 

ans =

    3.1414


er =

  -5.9352e-05


ifail =

                    0


function d01ga_example
x = [0;
     0.04;
     0.08;
     0.12;
     0.22;
     0.26;
     0.3;
     0.38;
     0.39;
     0.42;
     0.45;
     0.46;
     0.6;
     0.68;
     0.72;
     0.73;
     0.83;
     0.85;
     0.88;
     0.9;
     1];
y = [4;
     3.9936;
     3.9746;
     3.9432;
     3.8153;
     3.7467;
     3.6697;
     3.4943;
     3.4719;
     3.4002;
     3.3264;
     3.3014;
     2.9412;
     2.7352;
     2.6344;
     2.6094;
     2.3684;
     2.3222;
     2.2543;
     2.2099;
     2];
[ans, er, ifail] = d01ga(x, y)
 

ans =

    3.1414


er =

  -5.9352e-05


ifail =

                    0



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–2013