<s>[INST] Error finding Fourier series I want to find the Fourier series for 
$f(x)=\left\{\begin{array}{rcl} 0 & \mbox{ if } & -\pi \leq x \leq 0 \\ \sin x & \mbox{ if } & 0 < x < \pi  \end{array}\right.$
The Fourier series is given by $F=a_0+\sum (a_n\cos nx + b_n \sin nx)$
My problem is that both $a_n$ and $b_n$ vanish when I try to calculate them.
$$a_0=\frac{1}{2\pi}\int_{0}^{\pi}\sin x = -\frac{1}{2\pi}(\cos \pi - cos 0)= \frac{1}{\pi}$$
$$a_n=\frac{1}{\pi}\int_{0}^{\pi}\sin x\cos nx dx = \frac{1}{\pi}\left(-\cos x \cos nx - \frac{1}{n}\int \sin nx \cos x dx\right)$$
 $$=\frac{1}{\pi}\left(-\cos x\cos nx- \frac{1}{n} \left( - \frac{1}{n}\cos x\cos nx -\frac{1}{n}\int \sin x \cos nx dx  \right)\right)$$
 $$=\frac{1}{\pi}\left(-\cos x\cos nx+\frac{1}{n^2}\cos x \cos nx + \frac{1}{n^2}\int_{0}^{\pi}\sin x\cos nx dx\right)$$
 $$\Rightarrow \frac{1}{\pi}\int_{0}^{\pi}\sin x\cos nx dx = \frac{1}{\pi}\frac{(1/n^2-1)\cos x \cos nx}{1-1/n^2}|^\pi_0$$
$$=-\frac{1}{\pi}\cos x \cos nx |^\pi_0 =0$$
$$b_n=\frac{1}{\pi}\int_0^\pi \sin x \sin nx=\frac{1}{\pi}\frac{(1/n^2)\cos x\sin nx - (1/n)\sin x \cos nx}{1-1/n^2}|_0^\pi=0$$
 [/INST] $a_0=\frac{1}{\pi}\quad$ : OK.
$a_1=\frac{1}{\pi}\int_{0}^{\pi}\sin(x)\cos(x) dx = 0$
$a_n=-\frac{1}{\pi}\int_{0}^{\pi}\sin(x)\cos(nx) dx = -\frac{1}{\pi}\frac{1+\cos(n\pi)}{n^2-1}= -\frac{1}{\pi}\:\frac{1+(-1)^n}{n^2-1}\qquad \qquad n\geq 2$
$b_1=\frac{1}{\pi}\int_{0}^{\pi}\sin^2(x) dx =\frac{1}{2}$
$b_n=\frac{1}{\pi}\int_{0}^{\pi}\sin(x)\sin(nx) dx =0\qquad \qquad n\neq 1$
$$F(x)=\frac{1}{\pi}+\frac{1}{2}\sin(x)-\frac{1}{\pi}\sum_{n=2}^\infty \frac{1+(-1)^n}{n^2-1}\cos(nx)$$
$$F(x)=\frac{1}{\pi}+\frac{1}{2}\sin(x)-\frac{2}{\pi}\sum_{k=1}^\infty \frac{1}{4\:k^2-1}\cos(2kx)$$
Graphs of incomplete Fourier series :

</s>