Gauss Quadrature

  • MHB
  • Thread starter mathmari
  • Start date
  • #1
mathmari
Gold Member
MHB
5,053
7
Hey! :eek:

I am looking at the Gauss Quadrature to approximate integrals. I haven;t really understood the meaning of the weighting function. Could you explain that to me?

At each case, the points that we need depend on what weighting function we have, so which polynomials we consider or not?

For example, if we have the weighting function $w(x)=1$ we use the Legendre polynomials, and so their roots are the points that we need.
If we have $w(x)=\frac{1}{\sqrt{1-x^2}}$ we use the Chebychev-Polynomials.
If we have $w(x)=e^{-x^2}$ we use the Hermite polynomials.
If we have $w(x)=e^{-x}$ we use the Laguerre polynomials.
Right? Can we have also other weighting functions? (Wondering)


Suppose we have the integral $\displaystyle{\int_{-1}^1\frac{\cos (x)}{\sqrt{1-x^2}}\, dx}$ with weighting function $w(x)= \frac{1}{\sqrt{1-x^2}}$.

We approxmate the integral by the sum \begin{equation*}\sum_{i=1}^n\Phi (x_i)w_i\end{equation*}

So we use the Chebychev-polynomials, $T_n(x)=\cos \left (\arccos x\right ), \ x\in [-1,1]$. We get so the points \begin{equation*}x_k=\cos \left (\frac{2k+1}{2n}\pi \right ), \ \ k=0, \ldots n-1\end{equation*}

The constant weight are given by $w_i=\frac{\pi}{n+1}$.

Applying the Gauss quadrature with two weights and two points, so we use $w_1=w_2=\frac{\pi}{2+1}=\frac{\pi}{3}$ and $x_1=\cos \left (\frac{\pi}{4} \right )=\frac{1}{\sqrt{2}}$ and $x_2=\cos \left (\frac{3}{4}\pi \right )=-\frac{1}{\sqrt{2}}$, right? (Wondering)

Let $f(x)=\cos (x)$.

We have the following:
\begin{equation*}\int_{-1}^1f(x)\cdot w(x)\, dx\approx \sum_{i=1}^2 f (x_i)w_i=f (x_1)w_1+f (x_2)w_2=\cos \left (\frac{1}{\sqrt{2}}\right ) \cdot \frac{\pi}{3}+\cos \left (-\frac{1}{\sqrt{2}}\right )\cdot \frac{\pi}{3}\approx 1.59225\end{equation*}

Is this correct? (Wondering)
 
Last edited by a moderator:

Answers and Replies

  • #2
GJA
Gold Member
MHB
290
43
Hi mathmari,

Nice job showing the work you've done so far. There are a few points to clear up and I will do my best to parse them out. Since I don't know exactly what you do and don't know, feel free to ask any follow up questions if I mention something that's unclear.

I haven;t really understood the meaning of the weighting function. Could you explain that to me?

Weights are used in math to give more (or less) emphasis to certain types of data. You have most likely seen this when your instructor computes your final grade. For example, say you have a final exam grade worth 40%, 2 midterms worth 25% each, and a homework grade worth 10%. Your grade for the course would then be

(Final Exam Raw Percentage)*(.4) + (Midterm 1 + Midterm 2 Raw Percentage)*(.25) + (Homework Raw Percentage)*(.1).

In this way your instructor has mathematically placed more emphasis (i.e., weight) on, say, a 90% on the final exam than a 90% on your homework for the semester. The domain here (your scores for the course) is a discrete set, so when we calculate your weighted average, we need only use a standard summation.

It turns out that in many applications (e.g., probability theory, quantum mechanics) you need to work with continuous sets of data/outcomes. When this is the case, weight functions are used to place more (or less) emphasis on certain outcomes based (typically) on how likely you are to measure/observe a particular outcome. If you've taken a probability/stats course you have likely seen Gaussian/Normal distributions (among others). The example you gave of $w(x)=e^{-x^{2}}$ is (outside of a multiplicative factor) a Gaussian distribution/weight function with mean = 0 and variance = 1/2.

At each case, the points that we need depend on what weighting function we have, so which polynomials we consider or not?

For example, if we have the weighting function $w(x)=1$ we use the Legendre polynomials, and so their roots are the points that we need.
If we have $w(x)=\frac{1}{\sqrt{1-x^2}}$ we use the Chebychev-Polynomials.
If we have $w(x)=e^{-x^2}$ we use the Hermite polynomials.
If we have $w(x)=e^{-x}$ we use the Laguerre polynomials.
Right?

This is all correct, though I will add that the interval you are working on is also important. For example, when using the Laguerre polynomials you are thinking about problems on the half-line $(0,\infty)$, not $[-1,1]$.

Can we have also other weighting functions?

Yes, you can. In fact, quantum mechanics is, in a basic sense, essentially about finding different kinds of weight functions!

So we use the Chebychev-polynomials, $T_n(x)=\cos \left (\arccos x\right ), \ x\in [-1,1]$.

You are missing an $n$ here inside the parenthesis; i.e., $T_{n}(x)=\cos(n\arccos x).$

The constant weight are given by $w_i=\frac{\pi}{n+1}$.

This should be $\pi/n.$ There are two ways for checking this is incorrect: (1) Using Wolfram to check that the error you get when using these weights is quite large for the problem you are trying to solve; (2) (MORE IMPORTANTLY!) The method you use to derive the nodes $x_{i}$ and the weights $w_{i}$ is one that requires/forces the Gaussian quadrature to give EXACT equality in the case that $f(x)$ is a polynomial of degree $2n-1$ or smaller (due to linearity of integration, it is enough to check this using the monomials $1, x,\ldots, x^{2n-1}$). In particular, for $f(x)=1$ we have
$$\pi=\int_{-1}^{1}\frac{1}{\sqrt{1-x^{2}}}\,dx\neq w_{1}+w_{2} = \frac{2\pi}{3}.$$
I would try your calculation again. The "exact" value of the integral is 2.40394 (using Mathematica) and your new answer should be much closer to this than what you previously had.
 
Last edited:
  • #3
mathmari
Gold Member
MHB
5,053
7
Weights are used in math to give more (or less) emphasis to certain types of data. You have most likely seen this when your instructor computes your final grade. For example, say you have a final exam grade worth 40%, 2 midterms worth 25% each, and a homework grade worth 10%. Your grade for the course would then be

(Final Exam Raw Percentage)*(.4) + (Midterm 1 + Midterm 2 Raw Percentage)*(.25) + (Homework Raw Percentage)*(.1).

In this way your instructor has mathematically placed more emphasis (i.e., weight) on, say, a 90% on the final exam than a 90% on your homework for the semester. The domain here (your scores for the course) is a discrete set, so when we calculate your weighted average, we need only use a standard summation.

It turns out that in many applications (e.g., probability theory, quantum mechanics) you need to work with continuous sets of data/outcomes. When this is the case, weight functions are used to place more (or less) emphasis on certain outcomes based (typically) on how likely you are to measure/observe a particular outcome. If you've taken a probability/stats course you have likely seen Gaussian/Normal distributions (among others). The example you gave of $w(x)=e^{-x^{2}}$ is (outside of a multiplicative factor) a Gaussian distribution/weight function with mean = 0 and variance = 1/2.

Ah I see!


This is all correct, though I will add that the interval you are working on is also important. For example, when using the Laguerre polynomials you are thinking about problems on the half-line $(0,\infty)$, not $[-1,1]$.

Ah ok!



You are missing an $n$ here inside the parenthesis; i.e., $T_{n}(x)=\cos(n\arccos x).$

This should be $\pi/n.$ There are two ways for checking this is incorrect: (1) Using Wolfram to check that the error you get when using these weights is quite large for the problem you are trying to solve; (2) (MORE IMPORTANTLY!) The method you use to derive the nodes $x_{i}$ and the weights $w_{i}$ is one that requires/forces the Gaussian quadrature to give EXACT equality in the case that $f(x)$ is a polynomial of degree $2n-1$ or smaller (due to linearity of integration, it is enough to check this using the monomials $1, x,\ldots, x^{2n-1}$). In particular, for $f(x)=1$ we have
$$\pi=\int_{-1}^{1}\frac{1}{\sqrt{1-x^{2}}}\,dx\neq w_{1}+w_{2} = \frac{2\pi}{3}.$$
I would try your calculation again. The "exact" value of the integral is 2.40394 (using Mathematica) and your new answer should be much closer to this than what you previously had.

Yes, now I get an approximation that is much closer to the exact result! (Yes)


Thank you so much for your help! (Smile)
 
Last edited by a moderator:

Suggested for: Gauss Quadrature

  • Last Post
Replies
4
Views
473
Replies
6
Views
570
  • Last Post
Replies
12
Views
769
  • Last Post
Replies
18
Views
2K
  • Last Post
Replies
3
Views
1K
Replies
2
Views
895
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
16
Views
1K
Replies
6
Views
813
Top