(a) $f(x)=\begin{cases} 1 &\mbox{if } x\in [0,\pi )\\ -1 & \mbox{if } x\in [\pi, 2\pi) \end{cases}$
(b) $f(x)=\begin{cases} x(\pi-x) &\mbox{if } x\in [0,\pi )\\ (\pi-x)(x-2\pi) & \mbox{if } x\in [\pi, 2\pi) \end{cases}$
Any help will be appreciated. How can I find in general the fourier series of a piecewise function?
Essentially, when you perform the Fourier Series of a Piecewise Function, it is just as that function was a "picture" of one period of a periodic function with those characteristics.
I will work with the exponential form of the Fourier Series... It usually makes the integrals a little more friendly.
$$ \begin{align} x(t)&=X_{0}+\sum_{n=-\infty}^{-1}\left[X_{n}\cdot e^{j\cdot n\cdot \omega \cdot t}\right]+\sum_{n=1}^{\infty}\left[X_{n}\cdot e^{j\cdot n\cdot \omega \cdot t}\right]\\ X_{0}&=\frac{1}{T}\int_{T}x(t)dt\\ X_{n}&=\frac{1}{T}\int_{T}x(t)\cdot e^{-j\cdot n\cdot \omega \cdot t}dt \end{align} $$
So, let's start with problem (a):
Somethings we can notice by inspection: Mean Value is $0$ and it is an Real, Odd Function.
This means that for the Fourier Expansion, $X_{0}=0$ and $X_{n}$ will be purely imaginary and Odd.
To calculate $X_{n}$, we make $\omega=\frac{2\pi}{T}$ and follow up:
$$ \begin{align} X_{n}&=\frac{1}{T}\left[\int_{0}^{T/2}\exp\left(-j\frac{2\pi}{T}nt\right)-\int_{T/2}^{T}\exp\left(-j\frac{2\pi}{T}nt\right)\right]\\ \end{align} $$
Evaluating the integral, applying all necessary algebra and keeping in mind the recurrent angle relatiosns inside the trigonometric cycle, we have:
$$ \begin{align} X_{n}&=\frac{j}{n\pi}\left[\left(-1\right)^{n}-1\right]\\ \end{align} $$
Then, the Fourier Series solution for item (a) is:
$$x(t)=\sum_{n=-\infty}^{+\infty}\left\{\frac{j}{n\pi}\left[\left(-1\right)^{n}-1\right]\cdot e^{j\cdot n\cdot \omega \cdot t}\right\}$$
For $n\neq 0$.
We can also see that for even values of $n$, the argument of the sum is $0$.
Now, for problem (b):
After a brief analysis of the two pieces of the function, it is clear that the roots are: $0$, $\pi$ and $2\pi$ and both pieces have the same maximum value of $\frac{\pi^2}{4}$ which happen at $\frac{\pi}{2}$ and $\frac{3\pi}{2}$. If you plot this function, you would see that its shape resembles $|\sin(x)|$.
By inspection, we see that this is an Real, Even function and its Mean Value is $\neq 0$.
Which means that $X_{0}\neq 0$ and $X_{n}$ will be Even and Real.
Going on...
$$ \begin{align} X_{0}&=\frac{1}{T}\left[\int_{0}^{T/2}\left(-t^{2}+\pi t\right)dt+\int_{T/2}^{T}\left(-t^{2}+3\pi t-2\pi^{2}\right)dt\right]=\frac{\pi^{2}}{6}\\ \end{align} $$
Now, $X_{n}$:
$$ \begin{align} X_{n}&=\frac{1}{T}\left[\int_{0}^{T/2}\left(-t^{2}+\pi t\right)\exp\left(-j\frac{2\pi}{T}nt\right)dt+\int_{T/2}^{T}\left(-t^{2}+3\pi t-2\pi^{2}\right)\exp\left(-j\frac{2\pi}{T}nt\right)dt\right]\\ \end{align} $$
This integral will probably result in something pretty big, but the procedure is the same as done for (a).
Hope it was helpful.