<s>[INST] Find the fourier series of a piecewise continuous function 
Consider the function 
  $f(x) =
\begin{cases}
0 & & x \in [-\pi, 0) \\
1 & & x \in [0, \frac{\pi}{2})\\
0 & & x \in [\frac{\pi}{2}, \pi)\\
\end{cases}$
  Calculate its fourier series 

I am unsure if this is correct but i have:
$a_0=\frac{1}{2\pi} \int_{-\pi}^{\pi}f(x)dx=\frac{1}{2\pi} \int_{0}^{\frac{\pi}{2}}1dx=\frac{1}{2\pi}[x]_{0}^{\frac{\pi}{2}}=\frac{1}{4}$
$a_n=\frac{1}{\pi} \int_{-\pi}^{\pi}f(x)\cos(nx)dx=\frac{1}{\pi} \int_{0}^{\frac{\pi}{2}}\cos(nx)dx=\frac{1}{\pi}[\frac{1}{n}\sin(nx)]_{0}^{\frac{\pi}{2}}=\frac{1}{n\pi}$
$b_n=\frac{1}{\pi} \int_{-\pi}^{\pi}f(x)\sin(nx)dx=\frac{1}{\pi} \int_{0}^{\frac{\pi}{2}}\sin(nx)dx=\frac{1}{\pi}[\frac{1}{n}(-\cos(nx))]_{0}^{\frac{\pi}{2}}=\frac{-1}{n\pi}$
So we have $f(x)=\frac{1}{4}+\sum_{n=0}^{\infty}[\frac{1}{n\pi} \cos(nx) - \frac{1}{\pi} \sin(nx)]$
Is this correct?

 [/INST] The setup is alright but the evaluations are not correct. For example
$$
\dfrac{1}{\pi} \int_0^{\pi/2} \sin(nx) \; dx = \dfrac{1 - \cos(n \pi/2)}{n \pi}  \neq - \dfrac{1}{n \pi}
$$
</s>