I am trying to expand the following piecewise function as a cosine series:
$$ f(x)= \begin{cases} 3 & -7 < x < -1 \\ 8 & -1\leq x\leq 1 \\ 3 & 1 \leq x < 7 \end{cases} $$
The expansion should be in the form of: $$ f(x) = \frac{a_0}{2}+\sum_{n=1}^\infty{a_n\cos{\frac{n\pi}{p}x}} $$
My attempt at a solution: $$ 2a_0 = \frac{2}{L}\int_0^L f(x) \ dx \\ 2a_0 = \frac{2}{6}\int_1^7 3 \ dx + 2\int_{0}^1 8 \ dx \\ 2a_0 = 22 \\ a_0 = 11$$
For $a_n$: $$ a_n = \frac{2}{L}\int_0^L f(x) \cos{\frac{\pi nx}{L}} \ dx \\ a_n = \frac{2}{6}\int_1^7 3\cos{\frac{\pi nx}{6}} \ dx + 2\int_{0}^1 8\cos{\frac{\pi nx}{1}} \ dx \\ a_n = \frac{3\sin{\frac{7 \pi n}{6}}}{\pi n} - \frac{3\sin{\frac{\pi n}{6}}}{\pi n} + \frac{16\sin{\frac{\pi n}{6}}}{\pi n} $$
However, my solution is incorrect.. and I'm not sure what I'm doing wrong.