hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_quad_1d_gauss_wgen (d01bc)

Purpose

nag_quad_1d_gauss_wgen (d01bc) 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.

Syntax

[weight, abscis, ifail] = d01bc(itype, a, b, c, d, n)
[weight, abscis, ifail] = nag_quad_1d_gauss_wgen(itype, a, b, c, d, n)

Description

nag_quad_1d_gauss_wgen (d01bc) returns the weights wiwi and abscissae xixi for use in the summation
n
S = wif(xi)
i = 1
S=i=1nwif(xi)
which approximates a definite integral (see Davis and Rabinowitz (1975) or Stroud and Secrest (1966)). The following types are provided:
(a) Gauss–Legendre
b
Sf(x)dx,   exact for ​f(x) = P2n 1(x).
a
Sab f(x)dx,   exact for ​f(x)=P2n- 1(x).
Constraint: b > ab>a.
(b) Gauss–Jacobi
normal weights:
b
S(bx)c(xa)df(x)dx,   exact for ​f(x) = P2n1(x),
a
Sab(b-x)c(x-a)df(x)dx,   exact for ​f(x)=P2n-1(x),
adjusted weights:
b
Sf(x)dx,   exact for ​f(x) = (bx)c(xa)dP2n 1(x).
a
Sab f(x)dx,   exact for ​f(x)=(b-x)c(x-a)d P2n- 1(x).
Constraint: c > 1c>-1, d > 1d>-1, b > ab>a.
(c) Exponential Gauss
normal weights:
b
S|x(a + b)/2|cf(x)dx,   exact for ​f(x) = P2n1(x),
a
S ab | x- a+b 2 | c f(x)dx,   exact for ​f(x)=P2n-1(x),
adjusted weights:
b
Sf(x)dx,   exact for ​f(x) = |x(a + b)/2|cP2n 1(x).
a
S ab f(x)dx,   exact for ​f(x) = | x-a+b2 | c P2n- 1 (x).
Constraint: c > 1c>-1, b > ab>a.
(d) Gauss–Laguerre
normal weights:
S
|xa|cebxf(x)dx(b > 0),
a
a
|xa|cebxf(x)dx(b < 0),   exact for ​f(x) = P2n1(x),
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),
adjusted weights:
S
f(x)dx(b > 0),
a
a
f(x)dx(b < 0),   exact for ​f(x) = |xa|cebxP2n 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 > 1c>-1, b0b0.
(e) Gauss–Hermite
normal weights:
+
S|xa|ceb(xa)2f(x)dx,   exact for ​f(x) = P2n1(x),
S- +|x-a|ce-b (x-a) 2f(x)dx,   exact for ​f(x)=P2n-1(x),
adjusted weights:
+
Sf(x)dx,   exact for ​f(x) = |xa|ceb(xa)2P2n 1(x).
S- + f(x)dx,   exact for ​f(x)=|x-a|c e-b (x-a) 2 P2n- 1(x).
Constraint: c > 1c>-1, b > 0b>0.
(f) Rational Gauss
normal weights:
S
(|xa|c)/(|x + b|d)f(x)dx(a + b > 0),
a
a
(|xa|c)/(|x + b|d)f(x)dx(a + b < 0),   exact for ​f(x) = P2n1(1/(x + b)),
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 ) ,
adjusted weights:
S
f(x)dx(a + b > 0),
a
a
f(x)dx(a + b < 0),   exact for ​f(x) = (|xa|c)/(|x + b|d)P2n 1(1/(x + 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 > 1c>-1, d > c + 1d>c+1, a + b0a+b0.
In the above formulae, P2n1(x)P2n-1(x) stands for any polynomial of degree 2n12n-1 or less in xx.
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 =
(n − 1 ) ∑ Pj * (xi)2j = 0 − 1
wi= {j=0 n-1Pj* (xi) 2} -1
where Pj * (x)Pj*(x) is the jjth orthogonal polynomial with respect to the weight function over the appropriate interval.
The weights and abscissae produced by nag_quad_1d_gauss_wgen (d01bc) may be passed to nag_quad_md_gauss (d01fb), which will evaluate the summations in one or more dimensions.

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

Parameters

Compulsory Input Parameters

1:     itype – int64int32nag_int scalar
Indicates the type of quadrature rule.
itype = 0itype=0
Gauss–Legendre, with normal weights.
itype = 1itype=1
Gauss–Jacobi, with normal weights.
itype = -1itype=-1
Gauss–Jacobi, with adjusted weights.
itype = 2itype=2
Exponential Gauss, with normal weights.
itype = -2itype=-2
Exponential Gauss, with adjusted weights.
itype = 3itype=3
Gauss–Laguerre, with normal weights.
itype = -3itype=-3
Gauss–Laguerre, with adjusted weights.
itype = 4itype=4
Gauss–Hermite, with normal weights.
itype = -4itype=-4
Gauss–Hermite, with adjusted weights.
itype = 5itype=5
Rational Gauss, with normal weights.
itype = -5itype=-5
Rational Gauss, with adjusted weights.
Constraint: itype = 0itype=0, 11, -1-1, 22, -2-2, 33, -3-3, 44, -4-4, 55 or -5-5.
2:     a – double scalar
3:     b – double scalar
4:     c – double scalar
5:     d – double scalar
The parameters aa, bb, cc and dd which occur in the quadrature formulae. c is not used if itype = 0itype=0; d is not used unless itype = 1itype=1, -1-1, 55 or -5-5. For some rules c and d must not be too large (see Section [Error Indicators and Warnings]).
6:     n – int64int32nag_int scalar
nn, the number of weights and abscissae to be returned. If itype = -2itype=-2 or -4-4 and c0.0c0.0, an odd value of n may raise problems (see ifail = 6ifail=6).
Constraint: n > 0n>0.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     weight(n) – double array
The n weights.
2:     abscis(n) – double array
The n abscissae.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 ifail = 1ifail=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.
  ifail = 2ifail=2
On entry,n < 1n<1,
oritype < 5itype<-5,
oritype > 5itype>5.
If the soft fail option is used, weights and abscissae are returned as zero.
  ifail = 3ifail=3
a, b, c or d is not in the allowed range:
  • if itype = 0itype=0, abab;
  • if itype = ± 1itype=±1, abab or c1.0c-1.0 or d1.0d-1.0 or c + d + 2.0 > gmaxc+d+2.0>gmax;
  • if itype = ± 2itype=±2, abab or c1.0c-1.0;
  • if itype = ± 3itype=±3, b = 0.0b=0.0 or c1.0c-1.0 or c + 1.0 > gmaxc+1.0>gmax;
  • if itype = ± 4itype=±4, b0.0b0.0 or c1.0c-1.0 or (c + 1.0 / 2.0) > gmax(c+1.0/2.0)>gmax;
  • if itype = ± 5itype=±5, a + b = 0.0a+b=0.0 or c1.0c-1.0 or dc + 1.0dc+1.0.
Here gmaxgmax is the (machine-dependent) largest integer value such that Γ(gmax)Γ(gmax) can be computed without overflow.
If the soft fail option is used, weights and abscissae are returned as zero.
W ifail = 4ifail=4
One or more of the weights are larger than rmaxrmax, the largest floating point number on this machine. rmaxrmax is given by the function nag_machine_real_largest (x02al). If the soft fail option is used, the overflowing weights are returned as rmaxrmax. Possible solutions are to use a smaller value of n; or, if using adjusted weights, to change to normal weights.
W ifail = 5ifail=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.
W ifail = 6ifail=6
Exponential Gauss or Gauss–Hermite adjusted weights with n odd and c0.0c0.0. Theoretically, in these cases:
  • for c > 0.0c>0.0, the central adjusted weight is infinite, and the exact function f(x)f(x) is zero at the central abscissa.
  • for c < 0.0c<0.0, the central adjusted weight is zero, and the exact function f(x)f(x) 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  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(x)f(x) is involved.

Accuracy

The accuracy depends mainly on nn, with increasing loss of accuracy for larger values of nn. Typically, one or two decimal digits may be lost from machine accuracy with n20n20, and three or four decimal digits may be lost for n100n100.

Further Comments

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

Example

This example returns the abscissae and (adjusted) weights for the seven-point Gauss–Laguerre formula.
function nag_quad_1d_gauss_wgen_example
% Initialize variables and arrays.
itype = -3;
a =0;
b = 1;
c = 0;
d = 0;
n = 7;

fprintf('nag_quad_1d_gauss_wgen example program results\n\n');

[weight, abscis, ifail] = nag_quad_1d_gauss_wgen(int64(itype), a, b, c, d, int64(n));
if ifail ~= 0
    % Convergence problems, or input variables out of bounds.
    % Print message and exit.
    error('Warning: nag_quad_1d_gauss_wgen returned with ifail = %1d ',ifail);
end

% Output abscissae and weights.
fprintf('   Laguerre formula, %d points \n', n);
fprintf('    Abscissae         Weights \n')
for i = 1:n
    fprintf('   %10.5e     %10.5e \n',abscis(i),weight(i))
end
% Plot results.
fig = figure('Number', 'off');
display_plot(abscis, weight);

function plot(abscis, weight)
% Formatting for title and axis labels.
titleFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 14};
labFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 13};
set(gca, 'FontSize', 13); % for legend, axis tick labels, etc.
% Use a bar graph, and set the bar width.
bar1 = bar(abscis, weight);
set(bar1, 'BarWidth', 0.1);
% Set the title.
title(['Abscissae and Weights for the 7-point Gauss-Laguerre Formula ', ...
    '(a=0, b=1)'], titleFmt{:});
% Label the axes.
xlabel('x', labFmt{:});
ylabel('Weights at Abscissae', labFmt{:});
function display_plot(abscis, weight)
% Formatting for title and axis labels.
titleFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 14};
labFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 13};
set(gca, 'FontSize', 13); % for legend, axis tick labels, etc.
% Use a bar graph, and set the bar width.
bar1 = bar(abscis, weight);
set(bar1, 'BarWidth', 0.1);
% Set the title.
title(['Abscissae and Weights for the 7-point Gauss-Laguerre Formula ', ...
    '(a=0, b=1)'], titleFmt{:});
% Label the axes.
xlabel('x', labFmt{:});
ylabel('Weights at Abscissae', labFmt{:});
 
nag_quad_1d_gauss_wgen example program results

   Laguerre formula, 7 points 
    Abscissae         Weights 
   1.93044e-01     4.96478e-01 
   1.02666e+00     1.17764e+00 
   2.56788e+00     1.91825e+00 
   4.90035e+00     2.77185e+00 
   8.18215e+00     3.84125e+00 
   1.27342e+01     5.38068e+00 
   1.93957e+01     8.40543e+00 

function d01bc_example
% Initialize variables and arrays.
itype = -3;
a =0;
b = 1;
c = 0;
d = 0;
n = 7;

fprintf('d01bc example program results\n\n');

[weight, abscis, ifail] = d01bc(int64(itype), a, b, c, d, int64(n));
if ifail ~= 0
    % Convergence problems, or input variables out of bounds.
    % Print message and exit.
    error('Warning: d01bc returned with ifail = %1d ',ifail);
end

% Output abscissae and weights.
fprintf('   Laguerre formula, %d points \n', n);
fprintf('    Abscissae         Weights \n')
for i = 1:n
    fprintf('   %10.5e     %10.5e \n',abscis(i),weight(i))
end
% Plot results.
fig = figure('Number', 'off');
display_plot(abscis, weight);

function plot(abscis, weight)
% Formatting for title and axis labels.
titleFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 14};
labFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 13};
set(gca, 'FontSize', 13); % for legend, axis tick labels, etc.
% Use a bar graph, and set the bar width.
bar1 = bar(abscis, weight);
set(bar1, 'BarWidth', 0.1);
% Set the title.
title(['Abscissae and Weights for the 7-point Gauss-Laguerre Formula ', ...
    '(a=0, b=1)'], titleFmt{:});
% Label the axes.
xlabel('x', labFmt{:});
ylabel('Weights at Abscissae', labFmt{:});
function display_plot(abscis, weight)
% Formatting for title and axis labels.
titleFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 14};
labFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 13};
set(gca, 'FontSize', 13); % for legend, axis tick labels, etc.
% Use a bar graph, and set the bar width.
bar1 = bar(abscis, weight);
set(bar1, 'BarWidth', 0.1);
% Set the title.
title(['Abscissae and Weights for the 7-point Gauss-Laguerre Formula ', ...
    '(a=0, b=1)'], titleFmt{:});
% Label the axes.
xlabel('x', labFmt{:});
ylabel('Weights at Abscissae', labFmt{:});
 
d01bc example program results

   Laguerre formula, 7 points 
    Abscissae         Weights 
   1.93044e-01     4.96478e-01 
   1.02666e+00     1.17764e+00 
   2.56788e+00     1.91825e+00 
   4.90035e+00     2.77185e+00 
   8.18215e+00     3.84125e+00 
   1.27342e+01     5.38068e+00 
   1.93957e+01     8.40543e+00 


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013