Lab for Gauss-Legendre Quadrature

Module for Gauss-Legendre Quadrature

   Check out the new Numerical Analysis Projects page.

Background. Gauss-Legendre Quadrature. To approximate the integral [Graphics:gl.txtgr1.gif] by sampling [Graphics:gl.txtgr2.gif] at the n unequally spaced abscissas [Graphics:gl.txtgr3.gif] , where the corresponding weights are [Graphics:gl.txtgr4.gif] . 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".

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr9.gif]
 
 

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 [Graphics:gl.txtgr10.gif] .

Solution. First, enter the formula [Graphics:gl.txtgr11.gif] .

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr12.gif]

Solution using Gauss-Legendre quadrature with n = 2.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr13.gif]

Solution using Gauss-Legendre quadrature with n = 3.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr14.gif]

Solution using Gauss-Legendre quadrature with n = 4.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr15.gif]
 
[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr16.gif]

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr17.gif]

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr18.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 [Graphics:gl.txtgr19.gif] rule for n = 2, 3, and 4 points respectively.
Illustrate the comparisons for the integral [Graphics:gl.txtgr20.gif] .

Solution. Use Mathematica to find the true value of the integral and the "true" numerical value too.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr21.gif]

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.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr22.gif]

Compare Gauss-Legendre quadrature 3 point rule with Simpson's rule.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr23.gif]

Compare Gauss-Legendre quadrature 4 point rule with Simpson's [Graphics:gl.txtgr24.gif] rule.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr25.gif]

Observe that the errors for the Trapezoidal rule, Simpson's Rule and Simpson's [Graphics:gl.txtgr26.gif] rule form a decreasing sequence.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr27.gif]

Observe that the errors for the Gauss-Legendre quadrature rules for n = 2, 3, and 4 points form a decreasing sequence.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr28.gif]

The ratios will determine how much smaller the error for Gauss Legendre quadrature is.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr29.gif]

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.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr30.gif]
 
 

More Background. The shifted Gauss-Legendre rule for [a,b]. To approximate the integral [Graphics:gl.txtgr31.gif] use the change of variable [Graphics:gl.txtgr32.gif]. Then use [Graphics:gl.txtgr33.gif] and apply the Gauss-Legendre rules for [Graphics:gl.txtgr34.gif].

 

 

Exercise 3. Use the shifted Gauss-Legendre rules for n = 3 points to approximate the integrals
Illustrate the comparisons for the integral [Graphics:gl.txtgr35.gif] .

Solution. Enter the abscissas and weights. Copy them from Exercise 1 and make sure they are activated !

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr36.gif]

Exercise 3 (a). Find the integral over [0,1]

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr37.gif]

Compare with Mathematica's calculation.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr38.gif]

Exercise 3 (b). Find the integral over [1,2]

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr39.gif]

Compare with Mathematica's calculation.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr40.gif]

Exercise 3 (c). Find the integral over [2,3]

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr41.gif]

Compare with Mathematica's calculation.

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr42.gif]

What famous numbers do you recognize in the following list ?

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr43.gif]

Or perhaps the following list ?

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr44.gif]
 
[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr45.gif]

[Graphics:gl.txtgr6.gif][Graphics: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 [Graphics:gl.txtgr47.gif] 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.txtgr48.gif].

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr49.gif]

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr50.gif]

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr51.gif]

Use symbolic differentiation, and a graph to determine the bound [Graphics:gl.txtgr52.gif].

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr53.gif]

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr54.gif]

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr55.gif]

Use symbolic differentiation, and a graph to determine the bound [Graphics:gl.txtgr56.gif].

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr57.gif]

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr58.gif]

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr59.gif]

Now compare the actual error and error bounds for the quadrature rules.

For n = 2, [Graphics:gl.txtgr60.gif][Graphics:gl.txtgr61.gif] .

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr62.gif]

For n = 3, [Graphics:gl.txtgr63.gif][Graphics:gl.txtgr64.gif] .

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr65.gif]

For n = 4, [Graphics:gl.txtgr66.gif][Graphics:gl.txtgr67.gif] .

[Graphics:gl.txtgr6.gif][Graphics:gl.txtgr68.gif]
 

 

 

 

 

 

(c) John H. Mathews, 1998