MHB Understanding Gauss Quadrature for Approximating Integrals

  • Thread starter Thread starter mathmari
  • Start date Start date
  • Tags Tags
    Gauss
AI Thread Summary
Gauss Quadrature is used for approximating integrals, with the choice of weighting function determining the appropriate polynomial basis. Different weighting functions, such as $w(x)=1$ for Legendre polynomials or $w(x)=\frac{1}{\sqrt{1-x^2}}$ for Chebyshev polynomials, dictate the points and weights used in the approximation. The discussion highlights the importance of correctly calculating weights and points to achieve accurate results, emphasizing that errors can arise from incorrect assumptions about these values. The integral example provided illustrates the application of Chebyshev polynomials and the need for precise weights to match the exact integral value. Overall, understanding the role of weighting functions is crucial for effective integral approximation using Gauss Quadrature.
mathmari
Gold Member
MHB
Messages
4,984
Reaction score
7
Hey! :o

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:
Mathematics news on Phys.org
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.

mathmari said:
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.

mathmari said:
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]$.

mathmari said:
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!

mathmari said:
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).$

mathmari said:
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:
GJA said:
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!
GJA said:
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!
GJA said:
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:
Seemingly by some mathematical coincidence, a hexagon of sides 2,2,7,7, 11, and 11 can be inscribed in a circle of radius 7. The other day I saw a math problem on line, which they said came from a Polish Olympiad, where you compute the length x of the 3rd side which is the same as the radius, so that the sides of length 2,x, and 11 are inscribed on the arc of a semi-circle. The law of cosines applied twice gives the answer for x of exactly 7, but the arithmetic is so complex that the...
Is it possible to arrange six pencils such that each one touches the other five? If so, how? This is an adaption of a Martin Gardner puzzle only I changed it from cigarettes to pencils and left out the clues because PF folks don’t need clues. From the book “My Best Mathematical and Logic Puzzles”. Dover, 1994.
Back
Top