So I am currently looking at a fourier expansion for
$$f(x)=\left\{\begin{array}{ccl}\sin x &\text{ if }& x\in[0,\pi]\\0 & \text{ if } & x\in[\pi,2\pi]\end{array}\right.$$
I am working out $$a_n(f)=\frac{1}{\pi}\int_{0}^{2\pi}f(x) \cos (nx) dx = \frac{1}{\pi}\int_{0}^{\pi}\sin x \cos nx dx$$
Now i was unsure where to go from here and I looked at the answer where the next step is given as:
$$\frac{1}{2\pi}\int_{0}^{\pi} \sin ([n+1]x) - \sin ([n-1]x) dx$$
I really dont understand how they got to this, i feel like its probably a simple trick im missing but i dont understand the $n+1$ or $n-1$
many thanks
Probably it is easier to write $f(x)$ as $$ f(x)=\frac{1}{2}\left(\sin(x)+\left|\sin(x)\right|\right) $$ then recall that: $$ \left|\sin(x)\right| = \frac{2}{\pi}-\frac{4}{\pi}\sum_{n\geq 1}\frac{\cos(2nx)}{4n^2-1}.$$