Fourier series for $f(x)=\begin{cases} 0 & -\pi\leq x<0 \\\sin x & 0\leq x\leq \pi \end{cases}$ 
Find the Fourier series for $$f(x)=\begin{cases} 0 & -\pi\leq x<0 \\\sin x & 0\leq x\leq \pi  \end{cases}$$

I found an answer, I'm not completly sure if it's right.
The solution would be given by $$f(x)=a_0+\sum_n\left(a_n\cos\frac{n\pi x}{L}+b_n\sin\frac{n\pi x}{L}\right)$$
$$a_0=\frac{1}{2\pi}\int_0^\pi\sin x dx = - \frac{1}{2\pi}\cos x|_0^\pi=\frac{1}{\pi}.$$
$a_n=\displaystyle{\frac{1}{\pi}\int_0^\pi\sin x \cos nx dx}$, I compute then the indefinite integral first:
$$\int\sin x \cos nx dx=-n\cos x\cos nx - n\int\sin nx \cos x dx\;\;\;[1]\\=-n\cos x\cos nx-n\left(-\sin x \sin nx - n\int\sin x \cos nx\right)\;\;\;[2]\\=-n\cos x \cos nx + n\sin x \sin nx+ n\int \sin x \cos nx dx\\\implies \int sin x \cos nx = \frac{n}{1-n}(\sin x \sin nx - \cos x \cos nx)$$
The last integral evaluated from $0$ to $\pi$ is $-2$, then $a_n = -\displaystyle\frac{2}{\pi}$
$[1]:$ By parts with $u=\cos nx,dv=\sin x\;dx$
$[2]:$ Parts again with $u=\cos x, dv=\sin nx\;dx$
$b_n=\displaystyle{\frac{1}{\pi}\int_0^\pi\sin x \sin nx dx}$, as before I compute then the indefinite integral first:
$$\int \sin x \sin nx dx = -\frac{1}{n}\sin x \cos nx + \frac{1}{n}\int \cos x \cos nx\;\;\; [3]\\=-\frac{1}{n}\sin x \cos nx + \frac{1}{n}\left(\frac{1}{n}\cos x \sin nx + \frac{1}{n}\int \sin x \sin nx\right) \;\;\;[4]\\=-\frac{1}{n}\sin x \cos nx + \frac{1}{n^2}\cos x \sin nx + \frac{1}{n^2}\int \sin x \sin nx dx\\ \implies \int \sin x \sin nx dx = \frac{\frac{1}{n^2}cos x \sin nx - \frac{1}{n}\sin x \cos nx}{\left(1-1/n^2\right)}.$$
Then $b_n=0$ due to $\sin n\pi = \sin 0 = 0$.
$[3]:$ Parts with $u=\sin x, dv = \sin nx$
$[4]:$ Parts with $u=\cos x, dv=\cos nx$
This together gives the Fourier series
$$f(x) = \frac{1}{\pi}-\frac{2}{\pi}\sum_{n=1}^{\infty}\cos nx$$
Is this solution correct?
 A: To avoid partial integration, a complex approach:
\begin{align}
a_n&=\frac{1}{\pi}\int_0^\pi\sin(x)\cos(nx)dx\\
&=\frac{1}{4\pi i}\int_0^\pi(e^{ix}-e^{-ix})(e^{inx}+e^{-inx})dx\\
&=\frac{1}{4\pi i}\int_0^\pi e^{i(n+1)x}+e^{i(1-n)x}-e^{i(n-1)x}-e^{i(-1-n)x}dx\\
&=-\frac{1}{4\pi}\left[\frac{e^{i(n+1)x}}{n+1}+\frac{e^{i(1-n)x}}{1-n}-\frac{e^{i(n-1)x}}{n-1}-\frac{e^{i(-1-n)x}}{-1-n}\right]_0^\pi\qquad\text{$n\neq 1$}\\
&=-\frac{1}{4\pi}\left[\frac{e^{i(n+1)\pi}-1}{n+1}+\frac{e^{i(1-n)\pi}-1}{1-n}-\frac{e^{i(n-1)\pi}-1}{n-1}-\frac{e^{i(-1-n)\pi}-1}{-1-n}\right]\\
&=\cases{-\frac{2}{\pi(n^2-1)}\qquad&\text{if $n\geq 2$ even}\\
0\qquad&\text{if $n\geq3$ odd}}
\end{align}
For $a_1$, note that $\int_0^\pi\sin(x)\cos(x)dx=2\int_0^\pi\sin(2x)dx=0$.
Now we calculate $b_n$, using a product-to-sum-identity[Link]:
\begin{align}
b_n&=\frac{1}{\pi}\int_0^\pi\sin(x)\sin(nx)dx\\
&=\frac{1}{2\pi}\int_0^\pi\cos((n-1)x)-\cos((n+1)x)dx\\
&=\frac{1}{2\pi}\left[\frac{\sin((n-1)x)}{n-1}-\frac{\sin((n+1)x)}{n+1}\right]_0^\pi dx\\
&=0
\end{align}
The fact that $b_n=0$ corresponds with your solution, because $\sin(n\pi)=0$, with $n$ integer. Actually, using known identities is much more easier than partial integrating or a complex approach.
EDIT:
If this answer above was true, then $f(x)$ would be an even function, because it consists of only cosine terms. However, this is not the case. Because in the last calculation for $b_n$, there is a division by $n-1$, it should be noted that $n\geq2$. I completely forgot this. An additional calculation of $b_1$ is needed:
$$b_1=\frac{1}{\pi}\int_0^\pi\sin^2(x)dx=\frac{1}{2}$$
