Simple detailed worked examples using Gaussian Quadrature method

Nasser Abbasi

Introduction

We seek to find a numerical value for the definite integral of a real valued function of a real variable over a specific range. In other words, to evaluate MATH

Geometrically, this integral represents the area under $f\left( x\right) $ from $a$ to $b.$


d1.png

The following are few detailed step-by-step examples showing how to use Gaussian Quadrature (GQ) to solve this problem.

Few points to remember about GQ.

  1. There are different versions of GQ depending on the basis polynomials it uses which in turns determines the location of the integration points. We will only use GQ based on Legendre polynomials. The integration points (called $x_{i}$) are the roots of the Legendre polynomials.

  2. GQ gives an exact answer when the function to be integrated is a polynomial of order $2N-1$ where $N$ is the number of integration points.

  3. Since Legendre polynomials are defined over $[-1,1]$, we need to map the range of the function to be integrated to be $[-1,1]$. The actual integration is performed over $[-1,1]$ but the values are mapped back to the original range using a transformation rule. This diagram illustrates this.


    d3.png

    See appendix to see how the transformation rule is derived.

  4. To be consistent, we follow the book notations and call the user function to be integrated as MATH and the mapped function as $f\left( x\right) $.

  5. Using GQ, we need to have access to a lookup table to obtain the values of the weights (called Multipliers or $\alpha _{i}$ in the book) and the integration points $x_{i}$. For each different value of $N$ (the numbers of integration points, also called the order of GQ), there will be a specific set of values $\alpha _{i}$ and $x_{i}$ to use. Once we have $\alpha _{i}$ and $x_{i}$ then the value of the integral is
    MATH


The Algorithm

This is an overview of the GQ algorithm. Next we will work out few examples to illustrate.


qg_algorithm.png


Examples

example 1




Evaluate MATH, Use $N=5$

We see that $a=0$, MATH

Answer

step 1: $N$ is given, go to step 2.

step 2: From lookup we see that MATH

And

MATH

step 3: Evaluate the integral

LOOP over all the points from left to right.

MATH

But MATH

Hence MATH

Do the next point:

MATH But MATH

Hence

MATH

Do the next point MATH

But MATH

Hence

MATH

Do the next point

MATH But MATH

Hence

MATH

Do the next point

MATH But MATH

Hence

MATH

No more points. Add to obtain the final answer

MATH

To verify, use say Maple:


qg_example1.png


Example 2

Evaluate MATH

We see that $a=4$, MATH

Answer:

step 1: $N$ is not given. But since polynomial, we can determine minimum $N.$

Order of polynomial is $5$ hence we need $N=3$

step 2: From lookup we see that MATH

And

MATH

step 3: Evaluate the integral

LOOP over all the points from left to right.

MATH

But MATH

Hence MATH Do next point

MATH

But MATH

Hence MATH

Do next point

MATH

But MATH

Hence MATH

Hence the answer is

MATH

Verify


qg_example2.png


Example 3

Evaluate MATH

We see that $a=-1$, MATH

Answer:

step 1: $N$ is not given. But since polynomial, we can determine minimum $N.$

Order of polynomial is $5$ hence we need $N=3$

step 2: From lookup we see that MATH

And

MATH

step 3: Evaluate the integral

LOOP over all the points from left to right.

MATH

But MATH

Hence MATH Do next point

MATH

But MATH

Hence MATH

Do next point

MATH

But MATH

Hence MATH

Hence the answer is

MATH


Appendix

An easy way to find how the function changes when we change the range is to align the ranges over each others and take the ratio between them as the scale factor. This diagram shows this for a general case where we map $f\left( x\right) $ defined over $[a,b]$ to a new range defined over $[c_{1},c_{2}]$


d4.png

$\ $We see from the diagram that

MATH

But MATH

The above is called the Jacobian of the transformation.

Now, From the diagram we see that MATH

and

MATH

Hence (1) becomes

MATH

MATH

For the specific case when $c_{1}=-1$ and $c_{2}=+1$ the above expressions become

MATH

Which is the mapping used in the Gaussian Quadrature method.

It interesting to see the effect of this transformation on the shape of some functions. Below I plotted some functions under this transformation. The left plots are the original functions plotted over some range, in this case $[4,10]$ and the left side plots show the new shape (the function MATH) over the new range $[-1,1]$


mma_plots.png