Function Repository Resource:

ModifiedGaussianQuadratureWeights

Source Notebook

Get a numerically sorted list of abscissa-weight pairs for various modifications of Gaussian quadrature

Contributed by: Jan Mangaldan

ResourceFunction["ModifiedGaussianQuadratureWeights"][type,n]

gives a list of the n pairs {xi,wi} of the n-point modified Gaussian formula for quadrature on the interval -1 to 1, where wi is the weight of the abscissa xi.

ResourceFunction["ModifiedGaussianQuadratureWeights"][type,n,{a,b}]

rescales the Gaussian formula for the interval a to b.

ResourceFunction["ModifiedGaussianQuadratureWeights"][type,n,{a,b},prec]

uses the working precision prec.

Details

Modified Gaussian quadrature approximates the value of an integral as a linear combination of values of the integrand evaluated at optimal abscissas xi: .
Modified Gaussian quadrature formulae are obtained as appropriate modifications of the usual Gauss-Legendre quadrature formula to incorporate endpoint or error information.
The following modification types are supported:
"AntiGaussian"Laurie's anti-Gaussian quadrature formula
"Lobatto"Gauss–Lobatto quadrature with both endpoints fixed,
"RadauLeft"Gauss–Radau quadrature with left endpoint fixed,
"RadauRight"Gauss–Radau quadrature with right endpoint fixed,
The precision argument acts similarly to the WorkingPrecision option used in many Wolfram Language numeric functions; it is not at all like the PrecisionGoal option. If the n argument is too small to allow for a high-precision result, extra precision in a result will not be meaningful.

Examples

Basic Examples (3) 

The abscissas and weights for a 10-point Lobatto quadrature rule:

In[1]:=
ResourceFunction["ModifiedGaussianQuadratureWeights"]["Lobatto", 10]
Out[1]=

Lobatto quadrature rule over the interval 0 to 1:

In[2]:=
ResourceFunction[
 "ModifiedGaussianQuadratureWeights"]["Lobatto", 10, {0., 1.}]
Out[2]=

Use the specified precision:

In[3]:=
ResourceFunction[
 "ModifiedGaussianQuadratureWeights"]["Lobatto", 10, {0, 1}, 25]
Out[3]=

Scope (2) 

The abscissas and weights for a 10-point anti-Gaussian rule:

In[4]:=
ResourceFunction[
 "ModifiedGaussianQuadratureWeights"]["AntiGaussian", 10]
Out[4]=

The "RadauLeft" and "RadauRight" rules are basically reflections of each other over the integration interval:

In[5]:=
ResourceFunction[
 "ModifiedGaussianQuadratureWeights"]["RadauLeft", 5, {-1., 1.}]
Out[5]=
In[6]:=
ResourceFunction[
 "ModifiedGaussianQuadratureWeights"]["RadauRight", 5, {-1., 1.}]
Out[6]=

Applications (3) 

Use the modified Gaussian quadrature to approximate the area under a curve:

In[7]:=
f = x |-> Cos[x] + 3 x^3 - x + 3;

Compare the results of the various modifications with classical Gaussian quadrature for a fixed n:

In[8]:=
n = 5;
res = Table[
   With[{gq = ResourceFunction["ModifiedGaussianQuadratureWeights"][type, n, {-0.5, 1.5}]}, Total[#2 f[#1] & @@@ gq]], {type, {"AntiGaussian", "Lobatto", "RadauLeft", "RadauRight"}}];
PrependTo[res, With[{gq = ResourceFunction["GaussianQuadratureWeights"][n, {-0.5, 1.5}]}, Total[#2 f[#1] & @@@ gq]]];
TableForm[
 Transpose[{{"Gaussian", "AntiGaussian", "Lobatto", "RadauLeft", "RadauRight"}, res}], TableHeadings -> {None, {"Type", "Result"}}]
Out[8]=

Compare with the result of NIntegrate by computing the absolute error:

In[9]:=
ex = NIntegrate[f[x], {x, -0.5, 1.5}];
TableForm[
 Transpose[{{"Gaussian", "AntiGaussian", "Lobatto", "RadauLeft", "RadauRight"}, Abs[res - ex]}], TableHeadings -> {None, {"Type", "Absolute Error"}}]
Out[9]=

Version History

  • 1.0.0 – 03 May 2021

Source Metadata

Related Resources

License Information