d01 Chapter Contents
d01 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_quad_1d_gauss_wgen (d01tcc)

## 1  Purpose

nag_quad_1d_gauss_wgen (d01tcc) 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

 #include #include
 void nag_quad_1d_gauss_wgen (Nag_QuadType quad_type, double a, double b, double c, double d, Integer n, double weight[], double abscis[], NagError *fail)

## 3  Description

nag_quad_1d_gauss_wgen (d01tcc) 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 nag_quad_1d_gauss_wgen (d01tcc) may be passed to nag_quad_md_gauss (d01fbc), which will evaluate the summations in one or more dimensions.

## 4  References

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  Arguments

On entry: indicates the type of quadrature rule.
${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Legendre}$
Gauss–Legendre, with normal weights.
${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Jacobi}$
Gauss–Jacobi, with normal weights.
${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Jacobi_Adjusted}$
${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Exponential}$
Exponential Gauss, with normal weights.
${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Exponential_Adjusted}$
${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Laguerre}$
Gauss–Laguerre, with normal weights.
${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Laguerre_Adjusted}$
${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Hermite}$
Gauss–Hermite, with normal weights.
${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Hermite_Adjusted}$
${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Rational}$
Rational Gauss, with normal weights.
${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Rational_Adjusted}$
Constraint: ${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Legendre}$, $\mathrm{Nag_Quad_Gauss_Jacobi}$, $\mathrm{Nag_Quad_Gauss_Jacobi_Adjusted}$, $\mathrm{Nag_Quad_Gauss_Exponential}$, $\mathrm{Nag_Quad_Gauss_Exponential_Adjusted}$, $\mathrm{Nag_Quad_Gauss_Laguerre}$, $\mathrm{Nag_Quad_Gauss_Laguerre_Adjusted}$, $\mathrm{Nag_Quad_Gauss_Hermite}$, $\mathrm{Nag_Quad_Gauss_Hermite_Adjusted}$, $\mathrm{Nag_Quad_Gauss_Rational}$ or $\mathrm{Nag_Quad_Gauss_Rational_Adjusted}$.
3:     bdoubleInput
4:     cdoubleInput
5:     ddoubleInput
On entry: the parameters $a$, $b$, $c$ and $d$ which occur in the quadrature formulae. c is not used if ${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Legendre}$; d is not used unless ${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Jacobi}$, $\mathrm{Nag_Quad_Gauss_Jacobi_Adjusted}$, $\mathrm{Nag_Quad_Gauss_Rational}$ or $\mathrm{Nag_Quad_Gauss_Rational_Adjusted}$. For some rules c and d must not be too large (see Section 6).
Constraints:
• if ${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Legendre}$, ${\mathbf{a}}<{\mathbf{b}}$;
• if ${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Jacobi}$ or $\mathrm{Nag_Quad_Gauss_Jacobi_Adjusted}$, ${\mathbf{a}}<{\mathbf{b}}$ and ${\mathbf{c}}>-1.0$ and ${\mathbf{d}}>-1.0$;
• if ${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Exponential}$ or $\mathrm{Nag_Quad_Gauss_Exponential_Adjusted}$, ${\mathbf{a}}<{\mathbf{b}}$ and ${\mathbf{c}}>-1.0$;
• if ${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Laguerre}$ or $\mathrm{Nag_Quad_Gauss_Laguerre_Adjusted}$, ${\mathbf{b}}\ne 0.0$ and ${\mathbf{c}}>-1.0$;
• if ${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Hermite}$ or $\mathrm{Nag_Quad_Gauss_Hermite_Adjusted}$, ${\mathbf{b}}>0.0$ and ${\mathbf{c}}>-1.0$;
• if ${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Rational}$ or $\mathrm{Nag_Quad_Gauss_Rational_Adjusted}$, ${\mathbf{a}}+{\mathbf{b}}\ne 0.0$ and ${\mathbf{c}}>-1.0$ and ${\mathbf{d}}>{\mathbf{c}}+1.0$.
6:     nIntegerInput
On entry: $n$, the number of weights and abscissae to be returned. If ${\mathbf{quad_type}}=\mathrm{Nag_Quad_Gauss_Exponential_Adjusted}$ or $\mathrm{Nag_Quad_Gauss_Hermite_Adjusted}$ and ${\mathbf{c}}\ne 0.0$, an odd value of n may raise problems (see NE_INDETERMINATE).
Constraint: ${\mathbf{n}}>0$.
7:     weight[n]doubleOutput
On exit: the n weights.
8:     abscis[n]doubleOutput
On exit: the n abscissae.
9:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_CONSTRAINT
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{quad_type}}=〈\mathit{\text{value}}〉$.
NE_CONVERGENCE
The algorithm for computing eigenvalues of a tridiagonal matrix has failed to converge.
NE_INDETERMINATE
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.
NE_INT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}>0$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_TOO_BIG
One or more of the weights are larger than $\mathit{rmax}$, the largest floating point number on this computer (see nag_real_largest_number (X02ALC)): $\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.
NE_TOO_SMALL
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.

## 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 (d01tcce.c)

### 9.2  Program Data

Program Data (d01tcce.d)

### 9.3  Program Results

Program Results (d01tcce.r)