For the first example, I just want an example to show that the solution is exact for polynomials of degree ${\displaystyle 2n-1}$, using the ${\displaystyle n}$th degree Legendre polynomial. I'm going to approximate ${\displaystyle \int _{-1}^{1}x^{3}dx}$.

{\displaystyle {\begin{aligned}\int _{-1}^{1}x^{3}dx&=\left({\frac {1}{\sqrt {3}}}\right)^{3}+\left({\frac {-1}{\sqrt {3}}}\right)^{3}\\{\frac {1}{4}}1^{4}-{\frac {1}{4}}(-1)^{4}&=\left({\frac {1}{3{\sqrt {3}}}}\right)-\left({\frac {1}{3{\sqrt {3}}}}\right)\\{\frac {1}{4}}-{\frac {1}{4}}&=0\end{aligned}}}

This problem accurately illustrates the method for solving problems using the Gaussian Quadrature algorithm. Note that the zeros of the Legendre polynomials of degree ${\displaystyle n}$ are ${\displaystyle {\frac {1}{\sqrt {3}}}}$ and ${\displaystyle -{\frac {1}{\sqrt {3}}}}$.

We can see from the previous example that this method works quite well if we are integrating from ${\displaystyle -1}$ to ${\displaystyle 1}$, but in application, we rarely want to integrate over such a simple region. So in our next example, we will show that this technique is also effective if we change the limits of integration, as seen on the Wikipedia page, then we will solve the example ${\displaystyle \int _{4}^{14}x^{3}dx}$

{\displaystyle {\begin{aligned}\int _{4}^{14}x^{3}dx&={\frac {14-4}{2}}\sum _{i=1}^{2}f\left({\frac {14-4}{2}}x_{i}+{\frac {14+4}{2}}\right)\\{\frac {1}{4}}14^{4}-{\frac {1}{4}}4^{4}&=5\left(\left(5{\frac {1}{\sqrt {3}}}+9\right)^{3}+(\left(5{\frac {-1}{\sqrt {3}}}+9\right)^{3}\right)\\9540&=5\left({\frac {125}{3{\sqrt {3}}}}+{\frac {875}{3}}+{\frac {1215}{\sqrt {3}}}+729-{\frac {125}{3{\sqrt {3}}}}+{\frac {875}{3}}-{\frac {1215}{\sqrt {3}}}+729\right)\\9540&=5\left(1908\right)\\9540&=9540\end{aligned}}}

We will next show how to solve a problem that isn't a simple polynomial. We will approximate ${\displaystyle \int _{-1}^{1}e^{x}dx}$ using a two point Gaussian approximation, and discuss the error analysis.

{\displaystyle {\begin{aligned}\int _{-1}^{1}e^{x}dx&\approx e^{\frac {1}{\sqrt {3}}}+e^{\frac {-1}{\sqrt {3}}}\\e-{\frac {1}{e}}&\approx e^{\frac {1}{\sqrt {3}}}+{\frac {1}{e^{\frac {1}{\sqrt {3}}}}}\end{aligned}}}

We will next analyze this error, looking at the actual error followed by finding the error bound. We denote the approximation by ${\displaystyle f_{approx}}$ and the exact solution by ${\displaystyle f_{exact}}$.

{\displaystyle {\begin{aligned}\left|f_{exact}-f_{approx}\right|&=\left|e-{\frac {1}{e}}-e^{\frac {1}{\sqrt {3}}}-{\frac {1}{e^{\frac {1}{\sqrt {3}}}}}\right|\\&=0.00770629937787233598077\end{aligned}}}

The theoretical error bound when using the Legendre polynomial method is

{\displaystyle {\begin{aligned}\left|f_{exact}-f_{approx}\right|&\leq {\frac {(b-a)^{2n+1}(n!)^{4}}{(2n+1)\left[(2n)!\right]^{3}}}f^{(2n)}\left(\xi \right),a<\xi

In our example, the actual error was well within the error bound. We also see that with only two calculations, this is a very good algorithm for approximating integrals quickly with relatively good accuracy.

Exercises

1. Show that Gaussian Quadrature can solve exactly general cubic polynomials.

a) Set up the integral:

b) Evaluate the integral:

c) Evaluate the approximation:

d) Do parts b and c correspond?

2. Approximate ${\displaystyle \int _{-1}^{1}sin^{2}(x)cos(x)dx}$ using Gaussian Quadrature

a) Evaluate the problem symbolically:

b) Evaluate the approximation:

c) Find the actual error

d) Find the error bound

d) Is the actual error less than the error bound?

3. If ${\displaystyle x_{1},x_{2},....,x_{n}}$ are the roots of the ${\displaystyle n}$th Legendre Polynomial ${\displaystyle P_{n}(x)}$ and that for each ${\displaystyle i=1,2,....,n}$, the numbers ${\displaystyle c_{i}}$ are defined by

${\displaystyle c_{i}=\int _{-1}^{1}\prod _{j=1,j\neq i}^{n}{\frac {x-x_{j}}{x_{i}-x_{j}}}dx}$

Prove that if ${\displaystyle P(x)}$ is any polynomial of degree less than ${\displaystyle 2n}$, then

${\displaystyle \int _{-1}^{1}P(x)dx=\sum _{i=1}^{n}c_{i}P(x_{i}).}$

I realized that there was insufficient information after the derived and solved sample on Gaussian Quadrature thus i took the pain to edit this wikiversity page by adding a solved example to the information already on there and below is what i factored in.

Find the constants C_0, C_1, and x_1 so that the quadrature formula

${\displaystyle \int _{0}^{1}f(x)\,dx=C_{0}f(0)+C_{1}f(x_{1}).}$

has the highest possible degree of precision.

Solution

Since there are three unknowns, C_0, C_1 and x_1, we will expect the formula to be exact for

${\displaystyle f(x)=1,x,and\,\ x^{2}}$

Thus

${\displaystyle f(x)=1,\ \int _{0}^{1}f(x)\,dx=1=C_{0}+C_{1}\ \qquad \ Equation1,\qquad f(x)=x,\ \int _{0}^{1}f(x)\,dx={\frac {1}{2}}=C_{1}x_{1}\ \qquad \ Equation2.\qquad f(x)=x^{2},\ \int _{0}^{1}f(x)\,dx={\frac {1}{3}}=C_{1}x_{1}^{2}.}$

Equation 2 and 3 will yield.

${\displaystyle {\frac {c_{1}x_{1}}{c_{1}x_{1}^{2}}}=x_{1}={\frac {2}{3}}.\qquad C_{1}={\frac {3}{4}}.\qquad C_{0}={\frac {1}{4}}.}$

Hence

${\displaystyle \int _{0}^{1}f(x)\,dx={\frac {1}{4}}f(0)+{\frac {3}{4}}f({\frac {2}{3}})}$

Now,

${\displaystyle f(x)=x^{3}.\qquad \int _{0}^{1}x^{3}\,dx={\frac {1}{4}}}$

And

${\displaystyle {\frac {1}{4}}(0)^{3}+{\frac {3}{4}}({\frac {2}{3}})^{3}={\frac {2}{9}}.}$

Thus the degree of the precision is 2

Example Quiz

1 Why do we use the zeros of the Legendre polynomials in this method?

 By convention for consistency Because Legendre polynomials of degree ${\displaystyle n}$ are orthogonal to any other polynomial with degree less than ${\displaystyle n}$ Because they make ${\displaystyle f(x)=0}$ when approximating ${\displaystyle f(x)}$ None of these

2 The integral of a 6th degree polynomial can be approximated exactly using the 3rd degree Legendre polynomial, True or False

 True False

3 Calculate the error bound for a general 3rd degree polynomial using a 2nd order Legendre polynomial

 10.56 0 4.13 50.25

4 Calculate the error bound for ${\displaystyle \int _{4}^{8}x^{6}+5x^{5}+27x^{4}+108x+276dx}$ using a 3rd degree Legendre polynomial

 5.85 0.13 28.83 12.44

5 What are the failure conditions for this algorithm?

 The ${\displaystyle n}$th derivative of ${\displaystyle f(x)}$ must be nonzero ${\displaystyle f(x)}$ is discontinuous over the range of integration ${\displaystyle f(x)}$ is constant over the range The method never fails, it just can suffer from poor accuracy