(a) Extend the definition of f(x) to make it an even function f*(x),
and we take f* to be periodic over an interval of length P = 4. We compute the coefficients of the cosine series:
Note that a₀ = 1 (you can compute the integral again without the cosine, or just take the limit as n -> 0). For all other even integers n, the numerator vanishes, so we split off the odd case for n = 2k - 1 :
Then the cosine series of f(x) is
(b) For the sine series, you instead extend f(x) to an odd function f*(x),
Again, P = 4, and the coefficient of the sine series are given by
which we can again split into the even/odd cases,
So the sine series is
I've attached plots of the extended versions of f(x) along with the corresponding series up to degree 4.