I have been asked the following question, and I wonder why my answer incorrect:
$$f(x) = \sum_{k=1}^{10}(k^2\cdot cos(kx))$$
what is the value of the following integral? $$\int_{-\pi}^{\pi}f(x)\cdot cos(2x) dx$$
(long story short: the answer should be $4\pi$, but I get for some reason $0$)
$\int_{-\pi}^{\pi}\sum_{k=1}^{10}(k^2\cdot cos(kx)) \cdot cos(2x)dx = \int_{-\pi}^{\pi}\sum_{k=1}^{10}(k^2\cdot cos(kx)\cdot cos(2x))dx $
(cosine's multiplication trigonometric identity):
$\int_{-\pi}^{\pi}\sum_{k=1}^{10}(k^2\cdot \frac{1}{2}\cdot(cos(kx+2x)+cos(kx-2x)))dx $
(integral of sum $\equiv$ sum of integral):
$\sum_{k=1}^{10}(k^2\cdot \frac{1}{2})\cdot\int_{-\pi}^{\pi}(cos(kx+2x)+cos(kx-2x))dx $
$\rightarrow$ $\sum_{k=1}^{10}(k^2\cdot \frac{1}{2})\cdot (\frac{sin(kx + 2x)}{k + 2} + \frac{sin(kx - 2x)}{k - 2} )|_{x = -\pi}^{x= \pi}$
$(2\cdot \frac{sin(k\pi + 2\pi)}{k+2} + 2\cdot \frac{sin(k\pi - 2\pi)}{k-2}) \equiv (2\cdot \frac{0}{k+2} + 2\cdot \frac{0}{k-2}) \equiv 0$
$\rightarrow$ $\sum_{k=1}^{10}(k^2\cdot \frac{1}{2})\cdot 0 = 0$
I will be glad to know where am I wrong (my guess I couldn't "take out" the sum from the integral), and if there is an answer that doesn't forces me to write down explicitly $f(x)$.
Note that you have $k-2$ in the denominator. This is BAD, because $k=2$ is one of the values in your sum, so you have "divide by zero" in there.
You should have computed the $k=2$ term separately.
When $k=2$, we have $$ \int_{-\pi}^{\pi}(k^2\cdot \cos(kx)\cdot \cos(2x))\;dx \\= \int_{-\pi}^{\pi}(4\cdot \cos(2x)\cdot \cos(2x))\;dx \\= \int_{-\pi}^{\pi} 4\cos^2(2x)\;dx = 4\pi . $$
The rest of the terms yield $0$, as you correctly computed.