Gauss–Legendre quadrature weights and points
Syntax
Q = quadGaussLegendre(n)
Q = quadGaussLegendre(n,‘Domain’,[a,b])
Description
Q = quadGaussLegendre(n), where n is a positive integer, returns the n-point Gauss–Legendre quadrature rule Q as a stucture with fields Q.Points and Q.Weights, which store the n points (in ascending order) and corresponding weights, respectively, of the quadrature rule. An additional field, Q.Properties, stores the degree, type and interval, or domain, of the quadrature rule (the default domain is [-1,1]) in subfields .Degree, .Type and .Domain, respectively.
Q = quadGaussLegendre(n,’Domain’,[a,b]), same as above, but where the Name, Value pair ‘Domain’,[a,b] specifies the domain of integration for the quadrature rule. The default domain is the bi-unit interval [-1,1].
Note: An n-point Gauss–Legendre quadrature rule is of degree 2n-1; that is, it integrates all polynomial up to degree 2n-1 exactly.
Examples
Example 1 − Integrating a polynomial exactly using a sufficient number of Gauss–Legendre weights and points
Gauss–Legendre, or Gaussian, quadrature rules compute definite integrals via a weighted sum of function evaluations, i.e.,
where is the set quadrature weights and is the set of corresponding quadrature points at which the function is evaluated. In the case when is a polynomial of degree d, the equation can be made exact with a sufficient number of weights and points n. Specifically, an n-point Gauss–Legendre quadrature can compute the integral of all polynomials of degree exactly.
Consider, for example, evaluating the following integral using Gauss–Legendre quadrature
First, define the polynomial in Matlab® form
f = [2 3 0 3];
Next, obtain the weight and point for the 1-point Gauss–Legendre quadrature rule
Q = quadGaussLegendre(1)
Note this case corresponds to a simple midpoint rule, and the quadrature rule can be applied by simply taking the product of the quadrature weight and the polynomial evaluated at the quadrature point, i.e.,
I1 = Q.Weights*polyval(f,Q.Points)
I1 = 6
Since a 3rd-degree polynomial is being computed with a 1-point rule, which is only of degree 1, there is an error in the calculation (the exact value is 8). The degree of the quadrature rule can be checked by referring to the Q.Properties field, i.e.,
Q.Properties
where it can be noted that the rule is of degree 1. As noted above, an n-point Gauss-Legendre quadrature is required to integrate a degree polynomial exactly. So in this case, we need
n = ceil((3+1)/2)
n = 2
points to integrate the polynomial exactly. Obtaining the weights and points for the 2-point Gauss–Legendre rule
Q = quadGaussLegendre(2)
and then performing the weighted sum (by taking the dot product), it is found
I2 = dot(Q.Weights,polyval(f,Q.Points))
I2 = 8.0000
which is exact.
Example 2 − Integrating over a specified domain
The quadGaussLegendre function can be used to obtain points and weights applicable for integrating a function over a general interval , i.e.,
by specifying the additonal Name,Value pair ‘Domain’,[a,b]. For example, consider integration of the polynomial from the example above over the interval , i.e.,
To obtain a 2-point Gauss–Legendre quadrature rule for integrating over this domain, we use
Qab = quadGaussLegendre(2,‘Domain’,[0 4])
which has a different set of points and weights (computed in the function by simple transformations/scalings) than the “standard” 2-point quadrature rule for the (default) interval of that was obtained in the previous example, i.e.,
[ Q.Points, Qab.Points ]
[ Q.Weights, Qab.Weights]
This difference is also highlighted in the Qab.Properties field
Qab.Properties
where it can be noted that the domain field is specified as . Finally, applying the quadrature rule by taking the dot product of the quadrature weights and the function values at the corresponding quadrature points yields
Iab = dot(Qab.Weights,polyval(f,Qab.Points))
Iab = 204.0000
which is exact.
This function is part of……..