Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

## Purpose

nag_quad_1d_gauss_wres (d01tb) returns the weights and abscissae appropriate to a Gaussian quadrature formula with a specified number of abscissae. The formulae provided are for Gauss–Legendre, rational Gauss, Gauss–Laguerre and Gauss–Hermite.

## Syntax

[weight, abscis, ifail] = d01tb(key, a, b, n)
[weight, abscis, ifail] = nag_quad_1d_gauss_wres(key, a, b, n)

## Description

nag_quad_1d_gauss_wres (d01tb) returns the weights and abscissae for use in the Gaussian quadrature of a function $f\left(x\right)$. The quadrature takes the form
 $S=∑i=1nwifxi$
where ${w}_{i}$ are the weights and ${x}_{i}$ are the abscissae (see Davis and Rabinowitz (1975), Fröberg (1970), Ralston (1965) or Stroud and Secrest (1966)).
Weights and abscissae are available for Gauss–Legendre, rational Gauss, Gauss–Laguerre and Gauss–Hermite quadrature, and for a selection of values of $n$ (see Arguments).
 $S≃∫abfxdx$
where $a$ and $b$ are finite and it will be exact for any function of the form
 $fx=∑i=0 2n-1cixi.$
 $S≃∫a∞fx dx a+b> 0 or S≃∫-∞a fx dx a+b< 0$
and will be exact for any function of the form
 $fx=∑i=2 2n+1cix+bi=∑i=0 2n-1c2n+1-ix+bix+b2n+1.$
 $S≃∫a∞fx dx b> 0 or S≃∫-∞a fx dx b< 0$
and will be exact for any function of the form
 $fx=e-bx∑i=0 2n-1cixi.$
 $S≃∫-∞ +∞ fx dx$
and will be exact for any function of the form
 $fx=e-b x-a 2∑i=0 2n-1cixi b>0.$
 $S≃∫a∞e-bxfx dx b> 0 or S≃∫-∞a e-bxfx dx b< 0$
and will be exact for any function of the form
 $fx=∑i=0 2n-1cixi.$
 $S≃∫-∞ +∞ e-b x-a 2fx dx$
and will be exact for any function of the form
 $fx=∑i=0 2n-1cixi.$
Note:  the Gauss–Legendre abscissae, with $a=-1$, $b=+1$, are the zeros of the Legendre polynomials; the Gauss–Laguerre abscissae, with $a=0$, $b=1$, are the zeros of the Laguerre polynomials; and the Gauss–Hermite abscissae, with $a=0$, $b=1$, are the zeros of the Hermite polynomials.

## References

Davis P J and Rabinowitz P (1975) Methods of Numerical Integration Academic Press
Fröberg C E (1970) Introduction to Numerical Analysis Addison–Wesley
Ralston A (1965) A First Course in Numerical Analysis pp. 87–90 McGraw–Hill
Stroud A H and Secrest D (1966) Gaussian Quadrature Formulas Prentice–Hall

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{key}$int64int32nag_int scalar
${\mathbf{key}}=0$
Gauss–Legendre quadrature on a finite interval, using normal weights.
${\mathbf{key}}=3$
Gauss–Laguerre quadrature on a semi-infinite interval, using normal weights.
${\mathbf{key}}=-3$
${\mathbf{key}}=4$
Gauss–Hermite quadrature on an infinite interval, using normal weights.
${\mathbf{key}}=-4$
${\mathbf{key}}=-5$
Constraint: ${\mathbf{key}}=0$, $3$, $-3$, $4$, $-4$ or $-5$.
2:     $\mathrm{a}$ – double scalar
3:     $\mathrm{b}$ – double scalar
The quantities $a$ and $b$ as described in the appropriate sub-section of Description.
Constraints:
• Rational Gauss: ${\mathbf{a}}+{\mathbf{b}}\ne 0.0$;
• Gauss–Laguerre: ${\mathbf{b}}\ne 0.0$;
• Gauss–Hermite: ${\mathbf{b}}>0$.
4:     $\mathrm{n}$int64int32nag_int scalar
$n$, the number of weights and abscissae to be returned.
Constraint: ${\mathbf{n}}=1$, $2$, $3$, $4$, $5$, $6$, $8$, $10$, $12$, $14$, $16$, $20$, $24$, $32$, $48$ or $64$.
Note: if $n>0$ and is not a member of the above list, the maxmium value of $n$ stored below $n$ will be used, and all subsequent elements of abscis and weight will be returned as zero.

None.

### Output Parameters

1:     $\mathrm{weight}\left({\mathbf{n}}\right)$ – double array
The n weights.
2:     $\mathrm{abscis}\left({\mathbf{n}}\right)$ – double array
The n abscissae.
3:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W  ${\mathbf{ifail}}=1$
The n-point rule is not among those stored.
W  ${\mathbf{ifail}}=2$
Underflow occurred in calculation of normal weights.
W  ${\mathbf{ifail}}=3$
No nonzero weights were generated for the provided parameters.
${\mathbf{ifail}}=11$
Constraint: ${\mathbf{key}}=0$, $3$, $-3$, $4$, $-4$ or $-5$.
${\mathbf{ifail}}=12$
The value of a and/or b is invalid for the chosen key. Either:
• Constraint: $\left|{\mathbf{a}}+{\mathbf{b}}\right|>0.0$.
• Constraint: $\left|{\mathbf{b}}\right|>0.0$.
• Constraint: ${\mathbf{b}}>0.0$.
${\mathbf{ifail}}=14$
Constraint: ${\mathbf{n}}>0$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The weights and abscissae are stored for standard values of a and b to full machine accuracy.

Timing is negligible.

## Example

This example returns the abscissae and (adjusted) weights for the six-point Gauss–Laguerre formula.
```function d01tb_example

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

key = int64(-3);
a = 0;
b = 1;
n = int64(6);

[weight, abscis, ifail] = d01tb( ...
key, a, b, n);

fprintf('  Weights    Abscissae\n');
fprintf('%9.4f%12.4f\n',[weight abscis]');

function [fv, iflag, user] = f(x, nx, iflag, user)
fv = sin(x)./x.*log(10*(1-x));
```
```d01tb example results

Weights    Abscissae
0.5735      0.2228
1.3693      1.1889
2.2607      2.9927
3.3505      5.7751
4.8868      9.8375
7.8490     15.9829
```