in a Fourier series for function $$f(x)=\begin{cases}-1&\text{for }-\pi<x<0\\\sin x&\text{for }0<x<\pi\end{cases}$$ with $f(x)=f(x+ 2 \pi)$, is $f(x)= \dfrac{a_0}{2}+ \sum\limits_{n=1}^{ \infty}(a_n \cos nx+b_n \sin nx) $. we have:
$a_n=0, n=2k+1; b_n=0, n=2k$
I get stuck in this problem. How this coefficient was calculated? a bit more explanation was highly appreciated.
Here's my attempt: I'm not sure I get those answers either - are you sure they are right?
The formula for $a_{n}, b_{n}$ are: $$a_{n} = \frac{1}{L} \int\limits_{-L}^L f(x)cos(\frac{n\pi x}{L})dx $$ $$b_{n} = \frac{1}{L} \int\limits_{-L}^L f(x)sin(\frac{n\pi x}{L})dx $$
Since L is half the period, L = $\pi$ in this example.
$$ f(x) = \begin{cases} -1 & \text{if } -\pi< x < 0 \\ sin(x) & \text{if } 0 < x < pi \end{cases} $$
Then
$$a_{n} = \frac{1}{\pi} (\int\limits_{-\pi}^{0}-1cos(nx)dx + \int\limits_{0}^{\pi}sin(x)cos(nx) dx) = \frac{1}{\pi} \int\limits_{0}^{\pi}sin(x)cos(nx) dx = \frac{1}{\pi} \frac{cos(n\pi)+1}{1-n^2}$$
$$b_{n} = \frac{1}{\pi} (\int\limits_{-\pi}^{0}-1sin(nx)dx + \int\limits_{0}^{\pi}sin(x)sin(nx) dx)=\frac{1}{\pi} (\frac{cos(nx)}{n}|_{-\pi}^{0} + \frac{\pi}{2}) = \frac{1}{\pi} (\frac{1-(-1)^n}{n}+\frac{\pi}{2}) $$