D01 Chapter Contents
D01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD01BCF

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.

## 1  Purpose

D01BCF returns the weights (normal or adjusted) and abscissae for a Gaussian integration rule with a specified number of abscissae. Six different types of Gauss rule are allowed.

## 2  Specification

 SUBROUTINE D01BCF ( ITYPE, A, B, C, D, N, WEIGHT, ABSCIS, IFAIL)
 INTEGER ITYPE, N, IFAIL REAL (KIND=nag_wp) A, B, C, D, WEIGHT(N), ABSCIS(N)

## 3  Description

D01BCF returns the weights ${w}_{i}$ and abscissae ${x}_{i}$ for use in the summation
 $S=∑i=1nwifxi$
which approximates a definite integral (see Davis and Rabinowitz (1975) or Stroud and Secrest (1966)). The following types are provided:
(a) Gauss–Legendre
 $S≃∫ab fxdx, exact for ​fx=P2n- 1x.$
Constraint: $b>a$.
(b) Gauss–Jacobi
normal weights:
 $S≃∫abb-xcx-adfxdx, exact for ​fx=P2n-1x,$
 $S≃∫ab fxdx, exact for ​fx=b-xcx-ad P2n- 1x.$
Constraint: $c>-1$, $d>-1$, $b>a$.
(c) Exponential Gauss
normal weights:
 $S≃ ∫ab x- a+b 2 c fxdx, exact for ​fx=P2n-1x,$
 $S ≃ ∫ab fxdx, exact for ​fx = x-a+b2 c P2n- 1 x.$
Constraint: $c>-1$, $b>a$.
(d) Gauss–Laguerre
normal weights:
 $S ≃∫a∞x-ace-bxfxdx b>0, ≃∫-∞ax-ace-bxfxdx b<0, exact for ​fx=P2n-1x,$
 $S ≃∫a∞ fx dx b> 0, ≃∫-∞a fx dx b< 0, exact for ​fx=x-ace-bxP2n- 1x.$
Constraint: $c>-1$, $b\ne 0$.
(e) Gauss–Hermite
normal weights:
 $S≃∫-∞ +∞x-ace-b x-a 2fxdx, exact for ​fx=P2n-1x,$
 $S≃∫-∞ +∞ fxdx, exact for ​fx=x-ac e-b x-a 2 P2n- 1x.$
Constraint: $c>-1$, $b>0$.
(f) Rational Gauss
normal weights:
 $S ≃∫a∞x-acx+bdfxdx a+b>0, ≃∫-∞ax-acx+bdfxdx a+b<0, exact for ​fx=P2n-1 1x+b ,$
 $S ≃∫a∞ fx dx a+b> 0, ≃∫-∞a fx dx a+b< 0, exact for ​fx=x-acx+bd P2n- 1 1x+b .$
Constraint: $c>-1$, $d>c+1$, $a+b\ne 0$.
In the above formulae, ${P}_{2n-1}\left(x\right)$ stands for any polynomial of degree $2n-1$ or less in $x$.
The method used to calculate the abscissae involves finding the eigenvalues of the appropriate tridiagonal matrix (see Golub and Welsch (1969)). The weights are then determined by the formula
 $wi= ∑j=0 n-1Pj* xi 2 -1$
where ${P}_{j}^{*}\left(x\right)$ is the $j$th orthogonal polynomial with respect to the weight function over the appropriate interval.
The weights and abscissae produced by D01BCF may be passed to D01FBF, which will evaluate the summations in one or more dimensions.
Davis P J and Rabinowitz P (1975) Methods of Numerical Integration Academic Press
Golub G H and Welsch J H (1969) Calculation of Gauss quadrature rules Math. Comput. 23 221–230
Stroud A H and Secrest D (1966) Gaussian Quadrature Formulas Prentice–Hall

## 5  Parameters

1:     ITYPE – INTEGERInput
On entry: indicates the type of quadrature rule.
${\mathbf{ITYPE}}=0$
Gauss–Legendre, with normal weights.
${\mathbf{ITYPE}}=1$
Gauss–Jacobi, with normal weights.
${\mathbf{ITYPE}}=-1$
${\mathbf{ITYPE}}=2$
Exponential Gauss, with normal weights.
${\mathbf{ITYPE}}=-2$
${\mathbf{ITYPE}}=3$
Gauss–Laguerre, with normal weights.
${\mathbf{ITYPE}}=-3$
${\mathbf{ITYPE}}=4$
Gauss–Hermite, with normal weights.
${\mathbf{ITYPE}}=-4$
${\mathbf{ITYPE}}=5$
Rational Gauss, with normal weights.
${\mathbf{ITYPE}}=-5$
Constraint: ${\mathbf{ITYPE}}=0$, $1$, $-1$, $2$, $-2$, $3$, $-3$, $4$, $-4$, $5$ or $-5$.
2:     A – REAL (KIND=nag_wp)Input
3:     B – REAL (KIND=nag_wp)Input
4:     C – REAL (KIND=nag_wp)Input
5:     D – REAL (KIND=nag_wp)Input
On entry: the parameters $a$, $b$, $c$ and $d$ which occur in the quadrature formulae. C is not used if ${\mathbf{ITYPE}}=0$; D is not used unless ${\mathbf{ITYPE}}=1$, $-1$, $5$ or $-5$. For some rules C and D must not be too large (see Section 6).
6:     N – INTEGERInput
On entry: $n$, the number of weights and abscissae to be returned. If ${\mathbf{ITYPE}}=-2$ or $-4$ and ${\mathbf{C}}\ne 0.0$, an odd value of N may raise problems (see ${\mathbf{IFAIL}}={\mathbf{6}}$).
Constraint: ${\mathbf{N}}>0$.
7:     WEIGHT(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the N weights.
8:     ABSCIS(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the N abscissae.
9:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ 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\text{​ 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 $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
The algorithm for computing eigenvalues of a tridiagonal matrix has failed to obtain convergence. If the soft fail option is used, the values of the weights and abscissae on return are indeterminate.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{N}}<1$, or ${\mathbf{ITYPE}}<-5$, or ${\mathbf{ITYPE}}>5$.
If the soft fail option is used, weights and abscissae are returned as zero.
${\mathbf{IFAIL}}=3$
A, B, C or D is not in the allowed range:
• if ${\mathbf{ITYPE}}=0$, ${\mathbf{A}}\ge {\mathbf{B}}$;
• if ${\mathbf{ITYPE}}=±1$, ${\mathbf{A}}\ge {\mathbf{B}}$ or ${\mathbf{C}}\le -1.0$ or ${\mathbf{D}}\le -1.0$ or ${\mathbf{C}}+{\mathbf{D}}+2.0>\mathit{gmax}$;
• if ${\mathbf{ITYPE}}=±2$, ${\mathbf{A}}\ge {\mathbf{B}}$ or ${\mathbf{C}}\le -1.0$;
• if ${\mathbf{ITYPE}}=±3$, ${\mathbf{B}}=0.0$ or ${\mathbf{C}}\le -1.0$ or ${\mathbf{C}}+1.0>\mathit{gmax}$;
• if ${\mathbf{ITYPE}}=±4$, ${\mathbf{B}}\le 0.0$ or ${\mathbf{C}}\le -1.0$ or $\left({\mathbf{C}}+1.0/2.0\right)>\mathit{gmax}$;
• if ${\mathbf{ITYPE}}=±5$, ${\mathbf{A}}+{\mathbf{B}}=0.0$ or ${\mathbf{C}}\le -1.0$ or ${\mathbf{D}}\le {\mathbf{C}}+1.0$.
Here $\mathit{gmax}$ is the (machine-dependent) largest integer value such that $\Gamma \left(\mathit{gmax}\right)$ can be computed without overflow (see the Users' Note for your implementation for S14AAF).
If the soft fail option is used, weights and abscissae are returned as zero.
${\mathbf{IFAIL}}=4$
One or more of the weights are larger than $\mathit{rmax}$, the largest floating point number on this machine. $\mathit{rmax}$ is given by the function X02ALF. If the soft fail option is used, the overflowing weights are returned as $\mathit{rmax}$. Possible solutions are to use a smaller value of N; or, if using adjusted weights, to change to normal weights.
${\mathbf{IFAIL}}=5$
One or more of the weights are too small to be distinguished from zero on this machine. If the soft fail option is used, the underflowing weights are returned as zero, which may be a usable approximation. Possible solutions are to use a smaller value of N; or, if using normal weights, to change to adjusted weights.
${\mathbf{IFAIL}}=6$
Exponential Gauss or Gauss–Hermite adjusted weights with N odd and ${\mathbf{C}}\ne 0.0$. Theoretically, in these cases:
• for ${\mathbf{C}}>0.0$, the central adjusted weight is infinite, and the exact function $f\left(x\right)$ is zero at the central abscissa.
• for ${\mathbf{C}}<0.0$, the central adjusted weight is zero, and the exact function $f\left(x\right)$ is infinite at the central abscissa.
In either case, the contribution of the central abscissa to the summation is indeterminate.
In practice, the central weight may not have overflowed or underflowed, if there is sufficient rounding error in the value of the central abscissa.
If the soft fail option is used, the weights and abscissa returned may be usable; you must be particularly careful not to ‘round’ the central abscissa to its true value without simultaneously ‘rounding’ the central weight to zero or $\infty$ as appropriate, or the summation will suffer. It would be preferable to use normal weights, if possible.
Note:  remember that, when switching from normal weights to adjusted weights or vice versa, redefinition of $f\left(x\right)$ is involved.

## 7  Accuracy

The accuracy depends mainly on $n$, with increasing loss of accuracy for larger values of $n$. Typically, one or two decimal digits may be lost from machine accuracy with $n\simeq 20$, and three or four decimal digits may be lost for $n\simeq 100$.

The major portion of the time is taken up during the calculation of the eigenvalues of the appropriate tridiagonal matrix, where the time is roughly proportional to ${n}^{3}$.

## 9  Example

This example returns the abscissae and (adjusted) weights for the seven-point Gauss–Laguerre formula.

### 9.1  Program Text

Program Text (d01bcfe.f90)

None.

### 9.3  Program Results

Program Results (d01bcfe.r)