I have the function $$f(x)= \begin{cases} \frac{\pi}{2}+x & x \in (-\pi,0] \\ \frac{\pi}{2}-x & x \in (0,\pi]\\ \end{cases} $$
I need to extend it $2\pi$ periodically and then justify that
$$b_n=0, a_1=?, a_2=0$$
I understand the formula of a Fourier series; I have the formula for $a_0, a_n$, and $b_n$; but I am unsure how to extend and substitute in $f(x)$ if there are two different possibilities?
Many thanks.
I am not completely sure what your question is, so I'm sorry if I misunderstand you.
You have to integrate over the entire period, i.e on the interval $[-\pi, \pi]$ (the function is $2\pi$ periodic and therefore the interval should have length $2\pi$). Hence you have that
\begin{align} a_n &= \frac1\pi\int_{-\pi}^\pi f(x)\cos (n x)\,\mathrm{d}x\\ b_n &= \frac1\pi\int_{-\pi}^\pi f(x)\sin(nx)\,\mathrm{d}x. \end{align}
Remember that you can split up the integral if that makes it easier for you, i.e.
\begin{align}\int_{-\pi}^\pi f(x) \cos(nx)\,\mathrm{d}x &=\int_{-\pi}^0 f(x) \cos(nx)\,\mathrm{d}x +\int_{0}^\pi f(x) \cos(nx)\,\mathrm{d}x\\ &=\int_{-\pi}^0 \left(\frac\pi 2 + x\right) \cos(nx)\,\mathrm{d}x +\int_{0}^\pi \left(\frac\pi 2 - x\right) \cos(nx)\,\mathrm{d}x. \end{align}