<s>[INST] Fourier series of function $f(x)=0$ if $-\pi$$f(x) = \begin{cases}0 & \text{if }-\pi<x<0, \\
\sin(x) & \text{if }0<x<\pi.
\end{cases}$$
My attempt:
I went the route of expanding this function with a complex Fourier series.
$$f(x) = \sum_{n=-\infty}^{+\infty} C_{n}e^{inx}$$
$$C_{n} = \frac {1}{2\pi} \int_{0}^{\pi} \frac {e^{ix}-e^{-ix}}{2i} e^{-inx} \,\mathrm dx = \frac {1}{\pi}\left(\frac {1}{1-n^2}\right)$$
because only even $n$ terms survive, odd $n$ are 0
$$
C_0 = \frac {1}{2\pi} \int_{0}^{\pi} \sin(x)\, \mathrm dx = \frac {1}{\pi} 
$$
so
$$
f(x) = \frac{1}{\pi} + \frac {1}{\pi} \left(\frac {e^{i2x}}{1-2^2} + \frac {e^{i4x}}{1-4^2}+\frac {e^{i6x}}{1-6^2}+\cdots\right) + \frac {1}{\pi} \left(\frac {e^{-i2x}}{1-2^2} + \frac {e^{-i4x}}{1-4^2}+\frac {e^{-i6x}}{1-6^2}+\cdots\right)
$$
In sine and cosine terms,
$$
f(x) = \frac{1}{\pi} + \frac {2}{\pi} \left(\frac {\cos(2x)}{1-2^2} + \frac {\cos(4x)}{1-4^2}+\frac {\cos(6x)}{1-6^2}+\cdots\right)
$$
But the answer in my book is given as
$$
f(x) = \frac{1}{\pi} + \frac{1}{2} \sin(x)+ \frac {2}{\pi} \left(\frac {\cos(2x)}{2^2-1} + \frac {\cos(4x)}{4^2-1}+\frac {\cos(6x)}{6^2-1}+\dotsb\right)$$
I don't understand how there is a sine term and the denominator of the cosines has $-1$.
 [/INST] The $\sin$ term comes form $n=1$ you can't devide by zero.
mh I calculated again, your $\cos(x)$ terms are right, there shouldn't be a $-$ in the denominator
For $$\int_0^\pi \sin(x) e^{inx}\, \mathrm{d} x = \frac{1+ e^{i \pi n}}{1-n^2}$$
we have to check the case $n=1$ seperate as we can't devide by zero.
The case $n=1$ give
$$\int_0^\pi \sin(x) \exp(x)\, \mathrm{d}x=\frac{i \pi }{2}$$
</s>