Numerical Analysis/Gaussian Quadrature

< Numerical Analysis

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

\begin{align}
\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{align}

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

We can see from the previous example that this method works quite well if we are integrating from -1 to 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 \int_4^{14} x^3 dx


\begin{align}
\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{align}

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


\begin{align}
\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{align}

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


\begin{align}
\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{align}

The theoretical error bound when using the Legendre polynomial method is


\begin{align}
\left|f_{exact}-f_{approx}\right| &\le \frac{(b-a)^{2n+1}(n!)^4}{(2n+1)\left[(2n)!\right]^3} f^{(2n)}\left(\xi\right), a<\xi<b \\
&\le \frac{2^5 2^4}{5*4!^3} e \\
&= \frac{2^9}{5*24^3} e \\
&= 0.02013542095154848322489
\end{align}

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 \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  x_1, x_2,...., x_n are the roots of the nth Legendre Polynomial P_n(x) and that for each i=1,2,....,n, the numbers c_i are defined by

 
c_i = \int_{-1}^1 \prod_{j=1,j\neq i}^n \frac{x-x_j}{x_i-x_j} dx

Prove that if P(x) is any polynomial of degree less than 2n, then

 
\int_{-1}^1 P(x) dx = \sum_{i=1}^n c_i P(x_i).

Gaussian Quadrature Example

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


\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


f (x) = 1,   x,  and \,     \ x^2

Thus


f (x)= 1,\  \int_{0}^1 f (x)\,dx= 1 = C_0 + C_1\  \qquad                  \ Equation 1,   \qquad


f (x)= x,\  \int_{0}^1 f (x)\,dx= \frac{1}{2} = C_1x_1\  \qquad             \ Equation 2.    \qquad


f (x)= x^2,\  \int_{0}^1 f (x)\,dx= \frac{1}{3} = C_1x_1^2.

Equation 2 and 3 will yield.


\frac{c_1x_1}{c_1x_1^2} = x_1 = \frac{2}{3}. \qquad   C_1=\frac{3}{4}. \qquad  C_0= \frac{1}{4}.

Hence


\int_{0}^1 f (x)\,dx = \frac{1}{4}f(0)+  \frac{3}{4}f(\frac{2}{3})

Now,


f(x)=x^3.\qquad  \int_{0}^1 x^3\,dx = \frac{1}{4}

And


\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 n are orthogonal to any other polynomial with degree less than n
Because they make f(x) = 0 when approximating 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 \int_4^8 x^6 + 5x^5 + 27x^4 + 108x + 276 dx using a 3rd degree Legendre polynomial

5.85
0.13
28.83
12.44

5. What are the failure conditions for this algorithm?

The nth derivative of f(x) must be nonzero
f(x) is discontinuous over the range of integration
f(x) is constant over the range
The method never fails, it just can suffer from poor accuracy

Your score is 0 / 0
This article is issued from Wikiversity - version of the Saturday, April 02, 2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.