Calculate the Fourier series
$$ f(x) = \left\{\begin{aligned} & 7\sin(x), && 0 \le x \le \pi\\ & 0, && \pi \le x \le 2\pi \end{aligned} \right.$$
I know that when $f(x+L) = f(x)$, for all real $x$, the Fourier series expansion is
$$f(x) = \dfrac{a_0}{2} + \sum_{n = 1}^{\infty} a_n \cos\left(n \tfrac{2\pi}{L}x \right) + b_n\sin\left(n \dfrac{2\pi}{L}x \right)$$
where
$$a_n = \dfrac{2}{L}\int\limits_{x_0}^{x_0+L}f(x)\cos\left( n \tfrac{2\pi}{L} x \right) dx \qquad x_0 \in \mathbb{R}$$
and $$b_n = \dfrac{2}{L}\int\limits_{x_0}^{x_0+L}f(x)\sin\left( n \tfrac{2\pi}{L} x \right) dx \qquad x_0 \in \mathbb{R}$$
But if we attempt to calculate $a_n$, we get $a_n = \dfrac{7}{\pi}\int^{\pi}_0 \sin(x)\cos(nx) dx$. For $n \ge 1$, I do not understand how to calculate this integral. Even If I use integration by parts, I still get an integral that is not solvable.
EDIT: To be honest, I am not even sure I got this part correct. We are supposed to have $-L \le x \le L$, but for this problem, we do not have a $-L$? Instead, we have $0 \le x \le 2\pi$. What is going on here? (This was corrected in the equations above.)
I would greatly appreciate it if people could please take the time to explain how to solve such a problem.
Hint: The Fourier series of a function $f$ in $[a,a+2\ell]$ with period $T=2\ell$ is $$f(x) = \dfrac{a_0}{2} + \sum_{i = 1}^{\infty} a_n \cos\left( \dfrac{n\pi x}{\ell} \right) + b_n\sin\left( \dfrac{n\pi x}{\ell} \right)$$ where \begin{eqnarray} a_0 &=& \dfrac{1}{\ell}\int_a^{a+2\ell}f(x) dx \\ a_n &=& \dfrac{1}{\ell}\int_a^{a+2\ell}f(x)\cos\left( \dfrac{n\pi x}{\ell} \right) dx \\ b_n &=& \dfrac{1}{\ell}\int_a^{a+2\ell}f(x)\sin\left( \dfrac{n\pi x}{\ell} \right) dx \end{eqnarray}
Edit: Here $a=0$ and $\ell=\pi$ then \begin{eqnarray} a_0 &=& \dfrac{1}{\pi}\int_0^\pi7\sin x\,dx\\ &=&\dfrac{7}{\pi}\int_0^\pi\sin x\,dx\\ &=&\color{blue}{\dfrac{14}{\pi}}\\ a_n&=&\dfrac{1}{\pi}\int_0^\pi7\sin x\cos nx\,dx\\ &=&\dfrac{7}{2\pi}\left(-\dfrac{\cos(1-n)x}{1-n}-\dfrac{\cos(1+n)x}{1+n}\right)_0^\pi\\ &=&\color{blue}{\dfrac{7}{\pi}\dfrac{(-1)^n+1}{1-n^2}} \end{eqnarray} for $n\neq1$ and when $n=1$ $$a_1=\dfrac{1}{\pi}\int_0^\pi7\sin x\cos x\,dx=\dfrac{7}{2\pi}\int_0^\pi\sin2x\,dx=\color{blue}{0}$$ also \begin{eqnarray} b_n &=&\dfrac{1}{\pi}\int_0^\pi7\sin x\sin nx\,dx\\ &=&\dfrac{-7}{2\pi}\int_0^\pi\cos(1+n)x-\cos(1-n)x\,dx\\ &=&\dfrac{-7}{2\pi}\left(\dfrac{\sin(1+n)x}{1+n}-\dfrac{\sin(1-n)x}{1-n}\right)_0^\pi\\ &=&\color{blue}{0}~,~(n>1)\\ b_1&=&\dfrac{1}{\pi}\int_0^\pi7\sin x\sin x\,dx\\ &=&\dfrac{7}{2\pi}\int_0^\pi1-\cos2 x\,dx\\ &=&\color{blue}{\dfrac{7}{2}} \end{eqnarray} thus $$\color{blue}{\boxed{f(x)=\dfrac{7}{\pi}+\dfrac{7}{2}\sin x+\dfrac{7}{\pi}\sum_{n=2}^\infty\dfrac{(-1)^n+1}{1-n^2}\cos nx}}$$ or $$\color{blue}{\boxed{f(x)=\dfrac{7}{\pi}+\dfrac{7}{2}\sin x-\dfrac{14}{\pi}\left(\dfrac{\cos 2x}{3}+\dfrac{\cos 4x}{15}+\dfrac{\cos 6x}{35}+\cdots\right)}}$$