# Why the sine fourier series of cosx is not $0$ in the interval $[0,\pi]$?

I was reviewing the Fourier series for an exam and one of the practice exercises was to find the cosine and sine series of $$f(x)=cos(x)$$ in the interval $$[0,\pi]$$. When I calculate the cosine series of course the result is $$a_0=0$$ and $$a_n=0$$ for $$n\neq 1$$, so the final result is only $$f(x)=cos(x)$$.

Nevertheless, when I try to calculate the sine series, as $$cos(x)$$ is an even function I suppose the result should be $$b_n=0$$, but instead I get $$b_n=\frac{4n}{\pi(n^2-1)}$$ for $$n$$ even. Is there something wrong here? or the result is just this one and there's a mistake in my understanding of the Fourier series?

The calculations I made were: $$b_n=\frac{2}{\pi}\int_0^\pi cosx\space sin(nx) \space dx=\frac{1}{\pi}\int_0^\pi sin[(1+n)x]-sin[(1-n)x]\space dx=\frac{1}{\pi}\left[-\frac{cos[(1+n)x]}{1+n}-\frac{cos[(1-n)x]}{n-1}\right]_0^\pi=\frac{1}{\pi}\left[\frac{1}{n+1}+\frac{1}{n-1}+\frac{(-1)^n}{n+1}+\frac{(-1)^n}{n-1}\right]$$ For $$n$$ odd $$b_n=0$$.But for $$n$$ even: $$b_n=\frac{1}{\pi}\left(\frac{4n}{n^2-1}\right)$$

Does this make sense? Thank you very much.

When you want to represent $$x\mapsto\cos x$$ in the interval $$[0,\pi]$$ as a series of the form $$\cos x=\sum_{n=1}^\infty b_n\sin(nx)\qquad(0 you have to be aware that series $$f(x)\sim{a_0\over2}+\sum_{n=1}^\infty\bigl(a_n\cos(nx)+b_n\sin(nx)\bigr)$$ refer to the interval $$[-\pi,\pi]$$. In $$(1)$$ nothing is required about the $$x$$-interval $$[-\pi,0]$$; on the other hand we want all $$a_n=0$$. This means that we should invent an $$f$$ which is odd, and is $$\equiv\cos x$$ on $$[0,\pi]$$. Such an $$f$$ is given by $$f(x):={\rm sgn}(x)\cos x\quad(0<|x|<\pi)\ ,$$ but the value of $$f$$ at $$0$$ and $$\pm\pi$$ is not quite as desired. For this $$f$$ all $$a_n=0$$, and we have $$b_n={1\over\pi}\int_{-\pi}^\pi{\rm sgn}(x)\cos x\sin(nx)\>dx={2\over\pi}\int_0^\pi\cos x\sin(nx)\>dx\ ,$$ as you had in your question. I'm taking your values $$b_n$$, and obtain the following figure. Note Gibbs' phenomenon at the jump points.