The following formula used in numerical integration but I do not understand where it comes from. Can somebody give me any hint? $$\int_{-\pi}^{\pi}f(x)\sin x dx=(1-\frac{8}{\pi^2})[f(\pi)-f(-\pi)]+\frac{16}{\pi^2}[f(\frac{\pi}{2})-f(\frac{-\pi}{2})]$$
-
Could it be an approximation of a series expansion of $f(x)$? – Henry Lee May 12 '19 at 22:33
-
1It gives an exact value when $f(x)=x^3$ – May 12 '19 at 22:35
-
It also gives an exact value for any even function. – Paul May 12 '19 at 23:01
-
@Paul, When the $f(x)=x^5$ the value of integration not exact – May 12 '19 at 23:03
1 Answers
It is basically Gaussian quadrature: we introduce the ansatz $$ \int_{[-\pi,\pi]}f(x)\sin(x)\approx \sum_{i=1}^n w_if(x_i) $$ for some conveniently chosen nodes $\{x_i\}$. The weights $\{w_i\}$ are determined by insisting that this approximation is exact for some conveniently chosen functions (e.g., the first $n$ monomials $\{x^i\}_{i\in[0,n-1]}$). Taking $\{x_i\}=\{-\pi,-\pi/2,\pi/2,\pi\}$, and requiring this ansatz to be exact for $f=1,x,x^2,x^3$ leads to the expression in the OP.
--
Equivalently, construct the polynomial that interpolates $\{(x_i,f(x_i))\}$ at the nodes $\{x_i\}=\{-\pi,-\pi/2,\pi/2,\pi\}$: $$ P_f(x)=\frac{4 \left(-2 f\left(\frac{\pi }{2}\right)+2 f\left(-\frac{\pi }{2}\right)-f(-\pi )+f(\pi )\right) x^3+4 \pi \left(-f\left(\frac{\pi }{2}\right)-f\left(-\frac{\pi }{2}\right)+f(-\pi )+f(\pi )\right) x^2+\pi ^2 \left(8 f\left(\frac{\pi }{2}\right)-8 f\left(-\frac{\pi }{2}\right)+f(-\pi )-f(\pi )\right) x-\pi ^3 \left(-4 f\left(\frac{\pi }{2}\right)-4 f\left(-\frac{\pi }{2}\right)+f(-\pi )+f(\pi )\right)}{6 \pi ^3} $$ and integrate explicitly.
-
-
-
-
By insisting that the ansatz is correct for $f=1,x,x^2,x^3$. You get a system of four linear equations in four unknowns $w_1,w_2,w_3,w_4$. The solution is $w_1=-1+\frac{8}{\pi^2}$, $w_2=-\frac{16}{\pi^2}$, $w_3=\frac{16}{\pi^2}$, and $w_4=1-\frac{8}{\pi^2}$. – AccidentalFourierTransform May 12 '19 at 23:27
-