# NAG CPP Interfacenagcpp::quad::dim1_gauss_wres (d01tb)

Settings help

CPP Name Style:

## 1Purpose

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

## 2Specification

```#include "d01/nagcpp_d01tb.hpp"
```
```template <typename WEIGHT, typename ABSCIS>

void function dim1_gauss_wres(const types::f77_integer key, const double a, const double b, const types::f77_integer n, WEIGHT &&weight, ABSCIS &&abscis, OptionalD01TB opt)```
```template <typename WEIGHT, typename ABSCIS>

void function dim1_gauss_wres(const types::f77_integer key, const double a, const double b, const types::f77_integer n, WEIGHT &&weight, ABSCIS &&abscis)```

## 3Description

dim1_gauss_wres 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=1nwif(xi)$
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 Section 5).
1. (a)Gauss–Legendre Quadrature:
 $S≃∫abf(x)dx$
where $a$ and $b$ are finite and it will be exact for any function of the form
 $f(x)=∑i=0 2n-1cixi.$
2. (b)Rational Gauss quadrature, adjusted weights:
 $S≃∫a∞f(x) dx (a+b>0) or S≃∫-∞a f(x) dx (a+b<0)$
and will be exact for any function of the form
 $f(x)=∑i=2 2n+1ci(x+b)i=∑i=0 2n-1c2n+1-i(x+b)i(x+b)2n+1.$
3. (c)Gauss–Laguerre quadrature, adjusted weights:
 $S≃∫a∞f(x) dx (b>0) or S≃∫-∞a f(x) dx (b<0)$
and will be exact for any function of the form
 $f(x)=e-bx∑i=0 2n-1cixi.$
4. (d)Gauss–Hermite quadrature, adjusted weights:
 $S≃∫-∞ +∞ f(x) dx$
and will be exact for any function of the form
 $f(x)=e-b (x-a) 2∑i=0 2n-1cixi (b>0).$
5. (e)Gauss–Laguerre quadrature, normal weights:
 $S≃∫a∞e-bxf(x) dx (b>0) or S≃∫-∞a e-bxf(x) dx (b<0)$
and will be exact for any function of the form
 $f(x)=∑i=0 2n-1cixi.$
6. (f)Gauss–Hermite quadrature, normal weights:
 $S≃∫-∞ +∞ e-b (x-a) 2f(x) dx$
and will be exact for any function of the form
 $f(x)=∑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.

## 4References

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

## 5Arguments

1: $\mathbf{key}$types::f77_integer Input
On entry: indicates the quadrature formula.
${\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$
Gauss–Laguerre quadrature on a semi-infinite interval, using adjusted weights.
${\mathbf{key}}=4$
Gauss–Hermite quadrature on an infinite interval, using normal weights.
${\mathbf{key}}=-4$
Gauss–Hermite quadrature on an infinite interval, using adjusted weights.
${\mathbf{key}}=-5$
Rational Gauss quadrature on a semi-infinite interval, using adjusted weights.
Constraint: ${\mathbf{key}}=0$, $3$, $-3$, $4$, $-4$ or $-5$.
2: $\mathbf{a}$double Input
On entry: the parameters $a$ and $b$ which occur in the quadrature formulae described in Section 3.
Constraints:
• if ${\mathbf{key}}=-5$, ${\mathbf{a}}+{\mathbf{b}}\ne 0.0$;
• if ${\mathbf{key}}=3$ or $-3$, ${\mathbf{b}}\ne 0.0$;
• if ${\mathbf{key}}=4$ or $-4$, ${\mathbf{b}}>0.0$.
Constraints:
• Rational Gauss: ${\mathbf{a}}+{\mathbf{b}}\ne 0.0$;
• Gauss–Laguerre: ${\mathbf{b}}\ne 0.0$;
• Gauss–Hermite: ${\mathbf{b}}>0$.
3: $\mathbf{b}$double Input
On entry: the parameters $a$ and $b$ which occur in the quadrature formulae described in Section 3.
Constraints:
• if ${\mathbf{key}}=-5$, ${\mathbf{a}}+{\mathbf{b}}\ne 0.0$;
• if ${\mathbf{key}}=3$ or $-3$, ${\mathbf{b}}\ne 0.0$;
• if ${\mathbf{key}}=4$ or $-4$, ${\mathbf{b}}>0.0$.
Constraints:
• Rational Gauss: ${\mathbf{a}}+{\mathbf{b}}\ne 0.0$;
• Gauss–Laguerre: ${\mathbf{b}}\ne 0.0$;
• Gauss–Hermite: ${\mathbf{b}}>0$.
4: $\mathbf{n}$types::f77_integer Input
On entry: $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.
5: $\mathbf{weight}\left({\mathbf{n}}\right)$double array Output
On exit: the n weights.
6: $\mathbf{abscis}\left({\mathbf{n}}\right)$double array Output
On exit: the n abscissae.
7: $\mathbf{opt}$OptionalD01TB Input/Output
Optional parameter container, derived from Optional.

## 6Exceptions and Warnings

Errors or warnings detected by the function:
All errors and warnings have an associated numeric error code field, errorid, stored either as a member of the thrown exception object (see errorid), or as a member of opt.ifail, depending on how errors and warnings are being handled (see Error Handling for more details).
Raises: WarningException
$\mathbf{errorid}=1$
The n-point rule is not among those stored.
On entry: ${\mathbf{n}}=⟨\mathit{value}⟩$.
n-rule used: ${\mathbf{n}}=⟨\mathit{value}⟩$.
$\mathbf{errorid}=2$
Underflow occurred in calculation of normal weights.
Reduce n or use adjusted weights: ${\mathbf{n}}=⟨\mathit{value}⟩$.
$\mathbf{errorid}=3$
No nonzero weights were generated for the provided parameters.
Raises: ErrorException
$\mathbf{errorid}=11$
On entry, ${\mathbf{key}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{key}}=0,3,-3,4,-4\text{​ or ​}-5$.
$\mathbf{errorid}=12$
The value of a and/or b is invalid for Gauss-Laguerre quadrature.
On entry, ${\mathbf{key}}=⟨\mathit{value}⟩$.
On entry, ${\mathbf{a}}=⟨\mathit{value}⟩$ and ${\mathbf{b}}=⟨\mathit{value}⟩$.
Constraint: $|{\mathbf{b}}|>0.0$.
$\mathbf{errorid}=12$
The value of a and/or b is invalid for Gauss-Hermite quadrature.
On entry, ${\mathbf{key}}=⟨\mathit{value}⟩$.
On entry, ${\mathbf{a}}=⟨\mathit{value}⟩$ and ${\mathbf{b}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{b}}>0.0$.
$\mathbf{errorid}=12$
The value of a and/or b is invalid for rational Gauss quadrature.
On entry, ${\mathbf{key}}=⟨\mathit{value}⟩$.
On entry, ${\mathbf{a}}=⟨\mathit{value}⟩$ and ${\mathbf{b}}=⟨\mathit{value}⟩$.
Constraint: $|{\mathbf{a}}+{\mathbf{b}}|>0.0$.
$\mathbf{errorid}=14$
On entry, ${\mathbf{n}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{n}}>0$.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
Supplied argument has $⟨\mathit{\text{value}}⟩$ dimensions.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
Supplied argument was a vector of size $⟨\mathit{\text{value}}⟩$.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
The size for the supplied array could not be ascertained.
$\mathbf{errorid}=10602$
On entry, the raw data component of $⟨\mathit{\text{value}}⟩$ is null.
$\mathbf{errorid}=10603$
On entry, unable to ascertain a value for $⟨\mathit{\text{value}}⟩$.
$\mathbf{errorid}=-99$
An unexpected error has been triggered by this routine.
$\mathbf{errorid}=-399$
Your licence key may have expired or may not have been installed correctly.
$\mathbf{errorid}=-999$
Dynamic memory allocation failed.

## 7Accuracy

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

## 8Parallelism and Performance

Please see the description for the underlying computational routine in this section of the FL Interface documentation.

## 9Further Comments

Timing is negligible.

## 10Example

Examples of the use of this method may be found in the examples for: md_​gauss.