<s>[INST] Fourier series of a function in interval $[-\pi/2,\pi/2]$ I need to show that $$\frac{\cos x}{3}+\frac{\cos 3 x}{1 \cdot 3 \cdot 5}-\frac{\cos 5 x}{3 \cdot 5 \cdot 7}+\frac{\cos 7 x}{5 \cdot 7 \cdot 9}-\cdots=\frac{\pi}{8} \cos ^{2} x$$ on the interval $[-\pi/2,\pi/2]$. I have tried to find the Fourier coefficient $a_n$ with the formula $$a_n=\frac 2{\pi/2}\int_0^{\pi/2} \frac{\pi}{8}\cos^2(x)\cdot \cos \frac{n\pi x}{\pi/2}dx$$, but always end up getting something useless. How do I do it?
 [/INST] The way to think about this problem is to notice that LHS has period $2\pi$ and satisfies $f(x+\pi)=-f(x)$, while RHS has period $\pi$ so it satisfies $g(x+\pi)=g(x)$. This means that you need to extend $\cos^2(x)$ to the full interval $[-\pi,\pi]$ in such a way that it satisfies the same property as LHS, so you consider:
$h(x)=\cos^2(x)=\frac{1+\cos 2x}{2}, -\frac{\pi}{2} \le x \le \frac{\pi}{2}$,
$h(x)=-\cos^2(x)=-\frac{1+\cos 2x}{2}, -\pi \le x \le-\frac{\pi}{2}, \frac{\pi}{2} \le x \le \pi$
(Since $h$ is obviously continuos being $0$ where the expressions join, you can use $\le$ in both)
Now $h$ is even hence it has a Fourier cosine series and it is obvious that the even cosine part (including the free term) is zero (by periodicity the plus and minus parts cancel out), while the odd part has coefficients - for $k \ge 1$ corresponding to $\cos {(2k-1)x}$:
$\frac{1}{\pi}(\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\cos^2(x)\cos((2k-1)x)dx-\int_{-\pi}^{-\frac{\pi}{2}}\cos^2(x)\cos((2k-1)x)dx-\int_{\frac{\pi}{2}}^{\pi}\cos^2(x)\cos((2k-1)x)dx)=$
$\frac{4}{\pi}\int_{0}^{\frac{\pi}{2}}\cos^2(x)\cos((2k-1)x)dx=\frac{1}{\pi}((-1)^{k+1}\frac{2}{2k-1}+(-1)^{k}\frac{1}{2k-3}+(-1)^{k}\frac{1}{2k+1})$
and then for $k=1$ one gets $\frac{8}{3\pi}\cos x$, while for $k \ge 2$ we get  $(-1)^k\frac{8}{(2k-3)(2k-1)(2k+1)\pi}\cos{(2k+1)x}$ which is the expected value
Putting all together we get that:
$\frac{\cos x}{3}+\frac{\cos 3 x}{1 \cdot 3 \cdot 5}-\frac{\cos 5 x}{3 \cdot 5 \cdot 7}+\frac{\cos 7 x}{5 \cdot 7 \cdot 9}-\cdots=\frac{\pi}{8} \cos ^{2} x, -\frac{\pi}{2} \le x \le \frac{\pi}{2}$
$\frac{\cos x}{3}+\frac{\cos 3 x}{1 \cdot 3 \cdot 5}-\frac{\cos 5 x}{3 \cdot 5 \cdot 7}+\frac{\cos 7 x}{5 \cdot 7 \cdot 9}-\cdots=-\frac{\pi}{8} \cos ^{2} x, -\pi \le x \le -\frac{\pi}{2}, \frac{\pi}{2} \le x \le \pi$
</s>