![]()
![]()
Lab for Gauss-Legendre Quadrature
![]()
Background.
Gauss-Legendre Quadrature.
To approximate the integral
by sampling
at the n unequally spaced abscissas
, where the corresponding weights are
. The abscissas and weights are obtained from a table of values. For
convenience we will illustrate three cases and simplify the notation
by using single subscripted values.
The Gauss-Legendre quadrature rule for n = 2 points.
The Gauss-Legendre quadrature rule for n = 3 points.
The Gauss-Legendre quadrature rule for n = 4 points.
Load in Mathematica's graphics packages "Colors" and "FilledPlot".
Report to be handed in.
Computer Exercises
Exercise 1. Use the
Gauss-Legendre quadrature rules for n = 2, 3, and 4 points to compute
numerical approximations for
.
Solution. First, enter the formula
.
Solution using Gauss-Legendre quadrature with n = 2.
Solution using Gauss-Legendre quadrature with n = 3.
Solution using Gauss-Legendre quadrature with n = 4.
![]()
![[Graphics:gl.txtgr17.gif]](gl.txtgr17.gif)
Exercise 2. Compare the
accuracy of the Gauss-Legendre quadrature rules for n = 2, 3, and 4
points
with the Trapezoidal rule, Simpson's Rule and Simpson's
rule for n = 2, 3, and 4 points respectively.
Illustrate the comparisons for the integral
.
Solution. Use Mathematica to find the true value of the
integral and the "true" numerical value too.
Use the quadrature values obtained in Exercise 1.
Q2 = 1.69296344978122892
Q3 = 1.71202024520190976
Q4 = 1.71122450459948849
Compare Gauss-Legendre quadrature 2 point rule with the Trapezoidal
rule.
Compare Gauss-Legendre quadrature 3 point rule with Simpson's rule.
Compare Gauss-Legendre quadrature 4 point rule with Simpson's
rule.
Observe that the errors for the Trapezoidal rule, Simpson's Rule
and Simpson's
rule form a decreasing sequence.
Observe that the errors for the Gauss-Legendre quadrature rules for n = 2, 3, and 4 points form a decreasing sequence.
The ratios will determine how much smaller the error for Gauss Legendre quadrature is.
It is interesting to determine when the composite Simpson's rule is competitive with the three point Gauss Legendre rule, and compare the number of function evaluations. For our function above the following calculations are illustrative.
More Background.
The shifted Gauss-Legendre rule
for [a,b]. To approximate the integral
use the change of variable
.
Then use
and apply the Gauss-Legendre rules for
.
Exercise 3. Use the shifted
Gauss-Legendre rules for n = 3 points to approximate the
integrals
Illustrate the comparisons for the integral
.
Solution. Enter the abscissas and weights. Copy them from Exercise 1
and make sure they are activated !
Exercise 3 (a). Find the integral over [0,1]
Compare with Mathematica's calculation.
Exercise 3 (b). Find the integral over [1,2]
Compare with Mathematica's calculation.
Exercise 3 (c). Find the integral over [2,3]
Compare with Mathematica's calculation.
What famous numbers do you recognize in the following list ?
Or perhaps the following list ?
![]()
![[Graphics:gl.txtgr46.gif]](gl.txtgr46.gif)
Exercise 4. Investigate the
truncation error bound formulas for the Gauss-Legendre quadrature
rules of n = 2, 3, and 4 points.
Use the integral
for the investigation
Solution. Use the quadrature values obtained in Exercise 1.
Q2 = 1.69296344978122892
Q3 = 1.71202024520190976
Q4 = 1.71122450459948849
And use the "true" numerical value of the integral as found in
Exercise 2
v = 1.711248783784294
Use symbolic differentiation, and a graph to determine the bound
.
![]()
![[Graphics:gl.txtgr50.gif]](gl.txtgr50.gif)
Use symbolic differentiation, and a graph to determine the bound
.
![]()
![[Graphics:gl.txtgr54.gif]](gl.txtgr54.gif)
Use symbolic differentiation, and a graph to determine the bound
.
![]()
![[Graphics:gl.txtgr58.gif]](gl.txtgr58.gif)
Now compare the actual error and error bounds for the quadrature
rules.
For n = 2, ![]()
.
For n = 3, ![]()
.
For n = 4, ![]()
.
![]()
![]()
(c) John H. Mathews, 1998