Let $f :\mathbb R \to \mathbb R - \{2\pi \mathbb Z\}$ be the odd function of period $2\pi$ defined $$f (x)=\frac {\pi-x}{2}, \ \ \ \ \ \ \ \ \ x \in (0, \pi]$$ I have to find the Fourier series of $f $, however I can't understand a thing.
If I find the terms of the series by calculating $\int _0^{2\pi} f (x)e^{-inx}dx$ I obtain that $f_n=-\frac i {2n} $ ( the $f_n $ are the terms of the Fourier series of $f $); but f I integrate between $-\pi $ and $\pi$ (instead of $0$ and $2\pi$) I obtain that $f_n=(-1)^{n+1}\frac i {2n} $. This is due to this reason: $$\int_a^bf (x)e^{-inx}dx=\biggl [e^{-inx} \frac {i\pi-ix-1}{2n}\biggr]_a^b \; \; (\star)$$ so if $ (a,b)=(0,2\pi) $ the exponential factor is $1$ for every $n $, but if $(a,b)=(-\pi,\pi)$ that factor is equal to $ (-1)^n $. However the integration of a function with period $T$ must give the same result over each interval of length $T$, and $f (x)e^{-inx}$ has period $2\pi $ so there is something wrong. I don't think that the discontinuity is implied in this, and I don't think that ($\star$) could be wrong because the result in the solutions is $- \frac i {2n} $. Thank you in advance
This is good that you check that you should get the same answer both ways, and you are right that you should get the same answer.
My guess is that you made an error in your integration when doing the integral from $-\pi$ to $\pi$. What I get is $$\int_{0}^{\pi} f(x)e^{-inx}dx = \int_{0}^{\pi} \left(\frac{\pi-x}{2}\right)e^{-inx}dx = \frac{-i\pi n-(-1)^n+1}{2n^2}$$ $$\int_{-\pi}^{0} f(x)e^{-inx}dx = \int_{0}^{\pi} -\left(\frac{\pi+x}{2}\right)e^{-inx}dx = \frac{(-1)^n-in\pi-1}{2n^2}$$ so adding these together gives $$\frac{-i\pi}{n}$$ and multiplying by the $\frac{1}{2\pi}$ gives the desired Fourier coefficients. Note: I am using $f(x)=-f(-x)$ for $x\in[-\pi,0)$.