Approximation of the integral using Gauss-Legendre quadrature formula

Click For Summary

Discussion Overview

The discussion revolves around the approximation of the integral $$\int_0^{\pi}\sqrt{\sin (x)}\, dx$$ using the Gauss-Legendre quadrature formula with 2 nodes. Participants explore the properties of orthogonal polynomials and the application of quadrature methods, including the derivation of polynomial expressions and weight calculations.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant presents a quadrature formula and attempts to derive the polynomial $P_2(x)$, expressing uncertainty about the correctness of their approach.
  • Another participant suggests that the orthogonal polynomials should be defined on the interval $[-1,1]$ and questions the application of the recursive formulas for the interval $[0,\pi]$.
  • There is a discussion about the transformation of nodes and weights from the interval $[-1,1]$ to $[0,\pi]$, with differing interpretations of the correct approach.
  • Participants calculate the weights for the quadrature and express confusion regarding the signs and values, leading to discrepancies in the final approximation of the integral.
  • One participant identifies a potential sign mistake in the calculation of weights, which could affect the final result.
  • Another participant notes that the quadrature approximation will not yield the exact value of the integral due to the limited number of nodes, acknowledging an expected error margin.

Areas of Agreement / Disagreement

Participants express differing views on the correct application of the Gauss-Legendre quadrature method and the derivation of polynomials. There is no consensus on the correctness of the calculations or the expected results, as multiple interpretations and potential errors are discussed.

Contextual Notes

Participants highlight limitations in their calculations, including assumptions about the interval transformations and the inherent error in quadrature approximations with only 2 nodes.

mathmari
Gold Member
MHB
Messages
4,984
Reaction score
7
Hey! :giggle:

Let $\displaystyle{I_n(f)=\sum_{i=0}^na_if(x_i)}$ be a quadrature formula for the approximate calculation of the integral $I(f)=\int_a^bf(x)\, dx$.

Show that a polynomial $p$ of degree $2n+2$ exists such that $I_n(p)\neq I(p)$.

Calculate the approximation of the integral $$\int_0^{\pi}\sqrt{\sin (x)}\, dx$$ using Gauss-Legendre quadrature formula with $2$ nodes.
For the second part I have done the following :

We get the orthogonal polynomials by the recurive formula:
\begin{align*}&P_n(x)=(a_n+x)P_{n-1}(x)+c_nP_{n-2}(x) \\ &P_0=1, \ P_{-1}=0\end{align*} with \begin{equation*}a_n=-\frac{\langle x\cdot P_{n-1}, P_{n-1}\rangle_w}{\langle P_{n-1}, P_{n-1}\rangle_w}, \ \ \ , c_n=-\frac{\langle P_{n-1}, P_{n-1}\rangle_w}{\langle P_{n-2}, P_{n-2}\rangle_w}\end{equation*}
We have :
\begin{equation*}P_1(x)=(a_1+x)P_{0}(x)+c_1P_{-1}(x)=(a_1+x)\cdot 1+c_1\cdot 0=a_1+x \end{equation*}
We need to calculate $a_1$:
\begin{equation*}a_1=-\frac{\langle x\cdot P_{0}, P_{0}\rangle_w}{\langle P_{0}, P_{0}\rangle_w}=-\frac{\langle x, 1\rangle_w}{\langle 1, 1\rangle_w}\end{equation*}
We have that \begin{align*}&\langle x, 1\rangle_w=\int_0^{\pi}x\cdot 1\cdot w(x)\, dx=\int_0^{\pi} x\cdot 1\, dx =\frac{\pi^2}{2} \\ &\langle 1, 1\rangle_w=\int_0^{\pi}1\cdot 1\cdot 1\, dx=\int_0^{\pi} 1\, dx =\pi\end{align*}
So we have that $a_1=-\frac{\pi}{2}$. Therefore we get $P_1=-\frac{\pi}{2}+x$.

We have that
\begin{equation*}P_2(x)=(a_2+x)P_{1}(x)+c_2P_{0}(x)=(a_2+x)\cdot \left (-\frac{\pi}{2}+x\right )+c_2\end{equation*}
We need to calculate $a_2$ and $c_2$:
\begin{equation*}a_2=-\frac{\langle x\cdot P_{1}, P_{1}\rangle_w}{\langle P_{1}, P_{1}\rangle_w}=-\frac{\langle x\cdot \left (-\frac{\pi}{2}+x\right ), -\frac{\pi}{2}+x\rangle_w}{\langle -\frac{\pi}{2}+x, -\frac{\pi}{2}+x\rangle_w}=-\frac{\langle -\frac{\pi}{2}x+x^2, -\frac{\pi}{2}+x\rangle_w}{\langle -\frac{\pi}{2}+x, -\frac{\pi}{2}+x\rangle_w}\end{equation*}
We have that \begin{align*}&\langle -\frac{\pi}{2}x+x^2, -\frac{\pi}{2}+x\rangle_w=\int_0^{\pi}\left (-\frac{\pi}{2}x+x^2\right )\cdot \left (-\frac{\pi}{2}+x\right )\cdot 1\, dx=\frac{\pi^4}{24} \\ &\langle -\frac{\pi}{2}+x, -\frac{\pi}{2}+x\rangle_w=\int_0^{\pi}\left (-\frac{\pi}{2}+x\right )\cdot \left (-\frac{\pi}{2}+x\right )\cdot 1\, dx=\frac{\pi^3}{12}\end{align*}
So we have that $a_2=-\frac{\frac{\pi^4}{24}}{\frac{\pi^3}{12}}=-\frac{\pi}{2}$ and $c_2=-\frac{\langle P_{1}, P_{1}\rangle_w}{\langle P_{0}, P_{0}\rangle_w}=-\frac{\frac{\pi^3}{12}}{\pi}=-\frac{\pi^2}{12}$.
Therefore we get $P_2=(-\frac{\pi}{2}+x)\cdot \left (-\frac{\pi}{2}+x\right )-\frac{\pi^2}{12}$.

But this is not correct, is it? Do we not have to get $P_2(x)=\frac{1}{2}\left (3x^2-1\right )$ ? :unsure:
 
Last edited by a moderator:
Physics news on Phys.org
Hey mathmari,

According to wiki, we should use orthogonal polynomials on $[-1,1]$ with the convention that $P_n(1)=1$, and apply a change of interval to map it to $[0,\pi]$.
Your expected $P_2(x)=\frac 12(3x^2-1)$ is based on polynomials on $[-1,1]$.
But your calculations are on $[0,\pi]$ and it is not clear to me, which convention applies in that case, nor whether we can use the recursive formulas as given. :unsure:

The wiki page gives $x_i=\pm\frac{1}{\sqrt 3}$ and $w_i=1$ for a quadrature with 2 nodes on the interval $[-1,1]$.
If I apply a change of interval I think we get $\tilde x_i=\frac\pi 2\left(1\pm\frac 1{\sqrt 3}\right)$ and $\tilde w_i=\frac\pi 2$. :unsure:
 
Klaas van Aarsen said:
The wiki page gives $x_i=\pm\frac{1}{\sqrt 3}$ and $w_i=1$ for a quadrature with 2 nodes on the interval $[-1,1]$.
If I apply a change of interval I think we get $\tilde x_i=\frac\pi 2\left(1\pm\frac 1{\sqrt 3}\right)$ and $\tilde w_i=\frac\pi 2$. :unsure:

So the polynomial I found must be correct, right?

The nodes are the roots of $P_2(x)=x^2-\pi x+\frac{\pi^2}{6}$, which are $x_1=\frac\pi 2\left(1-\frac 1{\sqrt 3}\right)$, $x_2=\frac\pi 2\left(1+\frac 1{\sqrt 3}\right)$.

The weights are:
\begin{align*}w_1&= \int_0^{\pi}w(x)\prod_{j=1, j\neq 1}^2\frac{x-x_j}{x_1-x_j}\, dx=\int_0^{\pi}w(x)\cdot \frac{x-x_2}{x_1-x_2}\, dx=\int_0^{\pi}1\cdot \frac{x-\frac\pi 2\left(1+\frac 1{\sqrt 3}\right)}{\frac\pi 2\left(1-\frac 1{\sqrt 3}\right)-\frac\pi 2\left(1+\frac 1{\sqrt 3}\right)}\, dx\\ & =\int_0^{\pi}\frac{x-\frac\pi 2\left(1+\frac 1{\sqrt 3}\right)}{-\frac{\pi}{\sqrt{3}}}\, dx=\frac{\pi}{2}\\ w_2&=\int_0^{\pi}w(x)\prod_{j=1, j\neq 2}^2\frac{x-x_j}{x_2-x_j}\, dx=\int_0^{\pi}w(x)\frac{x-x_1}{x_2-x_1}\, dx=\int_0^{\pi}1\cdot \frac{x-\frac\pi 2\left(1-\frac 1{\sqrt 3}\right)}{\frac\pi 2\left(1-\frac 1{\sqrt 3}\right)-\frac\pi 2\left(1+\frac 1{\sqrt 3}\right)}\, dx \\ & =\int_0^{\pi} \frac{x-\frac\pi 2\left(1-\frac 1{\sqrt 3}\right)}{-\frac{\pi}{\sqrt{3}}}\, dx=-\frac{\pi}{2}\end{align*}
Therefore the formula is \begin{align*}&\int_0^{\pi}f(x)\, dx\approx \sum_{i=1}^2f(x_i)\cdot w_i=f(x_1)\cdot w_1+f(x_2)\cdot w_2 \\ & \Rightarrow \int_0^{\pi}\sqrt{\sin (x)}\, dx=\sqrt{\sin \left (\frac\pi 2\left(1-\frac 1{\sqrt 3}\right)\right )}\cdot \frac{\pi}{2}+\sqrt{\sin \left (\frac\pi 2\left(1+\frac 1{\sqrt 3}\right)\right )}\cdot \left (-\frac{\pi}{2}\right )=0.7850\cdot 1.5708-0.7850\cdot 1.5708=0\end{align*}
But this is not correct, shouldn't the result be about $2.3963$ ? Have I done something wrong at the calculations or is the formula wrong? I don't really see a mistake. :unsure:
 
mathmari said:
But this is not correct, shouldn't the result be about $2.3963$ ? Have I done something wrong at the calculations or is the formula wrong? I don't really see a mistake.
I believe $w_2$ should be $+\frac\pi 2$. If we substitute that, we get indeed about $2.3963$.
There seems to be a sign mistake where you substituted into $x_2-x_1$ in the denominator. 🤔
 
Klaas van Aarsen said:
I believe $w_2$ should be $+\frac\pi 2$. If we substitute that, we get indeed about $2.3963$.
There seems to be a sign mistake where you substituted into $x_2-x_1$ in the denominator. 🤔

Ah yes, you are right!

So we have:
\begin{align*}&\int_0^{\pi}f(x)\, dx\approx \sum_{i=1}^2f(x_i)\cdot w_i=f(x_1)\cdot w_1+f(x_2)\cdot w_2 \\ & \Rightarrow \int_0^{\pi}\sqrt{\sin (x)}\, dx=\sqrt{\sin \left (\frac\pi 2\left(1-\frac 1{\sqrt 3}\right)\right )}\cdot \frac{\pi}{2}+\sqrt{\sin \left (\frac\pi 2\left(1+\frac 1{\sqrt 3}\right)\right )}\cdot \frac{\pi}{2}=0.7850\cdot 1.5708+0.7850\cdot 1.5708=2.4662\end{align*}
There is a difference to $2.3963$,but is this a mistake at the calculations or is this an error because of the roundings? :unsure:
 
mathmari said:
So we have:
\begin{align*}&\int_0^{\pi}f(x)\, dx\approx 2.4662\end{align*}
There is a difference to $2.3963$,but is this a mistake at the calculations or is this an error because of the roundings?
Neither. (Shake)

It's a quadrature approximation with only 2 nodes. So we won't find the exact value of the integral.
Apparently the method has an error of about $0.07$ in this case. 🤔
 
Klaas van Aarsen said:
Neither. (Shake)

It's a quadrature approximation with only 2 nodes. So we won't find the exact value of the integral.
Apparently the method has an error of about $0.07$ in this case. 🤔

Ah ok, I see! Thank you very much! 🤩
 

Similar threads

  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
1K
  • · Replies 3 ·
Replies
3
Views
3K