How is the integral $2/π\int_{0}^{π} x^2\cos(nx) dx = \frac{4(-1)^n}{n^2}$? I thought it would be this :
$$2/π\int_{0}^{π} x^2\cos(nx) dx = 2/π\int_{0}^{π} x^2(-1)^n = 2/π(-1)^n\int_{0}^{π} x^2=\frac{2}{π(-1)^n}\biggl[\frac{x^3}{3}\biggr]_0^π =\frac{2(-1)^n}{3π^3}. $$
But it is actually $$\frac{2}{π}\int_{0}^{π} x^2\cos(nx) dx = \frac{4(-1)^n}{n^2}$$ according to my professor's notes. How did he get that answer?
Thanks.

Hint: Two times integrating by parts we get $$\int_{0}^{\pi}x^2\cos(nx)dx={\frac {{\pi}^{2}\sin \left( \pi\,n \right) {n}^{2}+2\,n\cos \left( 
\pi\,n \right) \pi-2\,\sin \left( \pi\,n \right) }{{n}^{3}}}
$$
