# NAG FL Interfaced01tcf (dim1_​gauss_​wgen)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

d01tcf 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.

## 2Specification

Fortran Interface
 Subroutine d01tcf ( a, b, c, d, n,
 Integer, Intent (In) :: itype, n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: a, b, c, d Real (Kind=nag_wp), Intent (Out) :: weight(n), abscis(n)
#include <nag.h>
 void d01tcf_ (const Integer *itype, const double *a, const double *b, const double *c, const double *d, const Integer *n, double weight[], double abscis[], Integer *ifail)
The routine may be called by the names d01tcf or nagf_quad_dim1_gauss_wgen.

## 3Description

d01tcf returns the weights ${w}_{i}$ and abscissae ${x}_{i}$ for use in the summation
 $S = ∑i=1n wi f(xi) ,$
which approximates a definite integral (see Davis and Rabinowitz (1975) or Stroud and Secrest (1966)). The following types are provided:
1. (a)Gauss–Legendre
 $S≃∫ab f(x)dx, exact for ​f(x)=P2n- 1(x).$
Constraint: $b>a$.
2. (b)Gauss–Jacobi
normal weights:
 $S≃∫ab(b-x)c(x-a)df(x)dx, exact for ​f(x)=P2n-1(x),$
 $S≃∫ab f(x)dx, exact for ​f(x)=(b-x)c(x-a)d P2n- 1(x).$
Constraint: $c>-1$, $d>-1$, $b>a$.
3. (c)Exponential Gauss
normal weights:
 $S≃ ∫ab |x- a+b 2 | c f(x)dx, exact for ​f(x)=P2n-1(x),$
 $S ≃ ∫ab f(x)dx, exact for ​f(x) = |x-a+b2| c P2n- 1 (x).$
Constraint: $c>-1$, $b>a$.
4. (d)Gauss–Laguerre
normal weights:
 $S ≃∫a∞|x-a|ce-bxf(x)dx (b>0), ≃∫-∞a|x-a|ce-bxf(x)dx (b<0), exact for ​f(x)=P2n-1(x),$
 $S ≃∫a∞ f(x) dx (b>0), ≃∫-∞a f(x) dx (b<0), exact for ​f(x)=|x-a|ce-bxP2n- 1(x).$
Constraint: $c>-1$, $b\ne 0$.
5. (e)Gauss–Hermite
normal weights:
 $S≃∫-∞ +∞|x-a|ce-b (x-a) 2f(x)dx, exact for ​f(x)=P2n-1(x),$
 $S≃∫-∞ +∞ f(x)dx, exact for ​f(x)=|x-a|c e-b (x-a) 2 P2n- 1(x).$
Constraint: $c>-1$, $b>0$.
6. (f)Rational Gauss
normal weights:
 $S ≃∫a∞|x-a|c|x+b|df(x)dx (a+b>0), ≃∫-∞a|x-a|c|x+b|df(x)dx (a+b<0), exact for ​f(x)=P2n-1 (1x+b ) ,$
 $S ≃∫a∞ f(x) dx (a+b>0), ≃∫-∞a f(x) dx (a+b<0), exact for ​f(x)=|x-a|c|x+b|d 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-1 Pj* (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 d01tcf 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

## 5Arguments

1: $\mathbf{itype}$Integer Input
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: $\mathbf{a}$Real (Kind=nag_wp) Input
3: $\mathbf{b}$Real (Kind=nag_wp) Input
4: $\mathbf{c}$Real (Kind=nag_wp) Input
5: $\mathbf{d}$Real (Kind=nag_wp) Input
On entry: the parameters $a$, $b$, $c$ and $d$ which occur in the quadrature formulae described in Section 3. 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: $\mathbf{n}$Integer Input
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: $\mathbf{weight}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the n weights.
8: $\mathbf{abscis}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the n abscissae.
9: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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 converge.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{itype}}=⟨\mathit{\text{value}}⟩$.
Constraint: $|{\mathbf{itype}}|<6$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}>0$.
${\mathbf{ifail}}=3$
On entry, a, b, c, or d is not in the allowed range: ${\mathbf{a}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{b}}=⟨\mathit{\text{value}}⟩$ ${\mathbf{c}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{d}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{itype}}=⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=4$
One or more of the weights are larger than $\mathit{rmax}$, the largest floating point number on this computer (see x02alf): $\mathit{rmax}=⟨\mathit{\text{value}}⟩$.
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.
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.
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.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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$.

## 8Parallelism and Performance

d01tcf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

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}$.

## 10Example

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

### 10.1Program Text

Program Text (d01tcfe.f90)

None.

### 10.3Program Results

Program Results (d01tcfe.r)