Solution (source code)

= Solution

Seek a periodic <particular solution> with <Fourier coefficients> $A_n,B_n$. Comparing constant terms gives $A_0=a_0/2$. Comparing the cosine and sine terms for $n\geq1$ gives
$$
2A_n+nB_n=a_n,\qquad -nA_n+2B_n=0,
$$
so $A_n=2a_n/(n^2+4)$ and $B_n=na_n/(n^2+4)$. Insert the coefficients from part (a) and add the <homogeneous solution>:
$$
\boxed{y(x)=Ce^{-2x}+\frac1\pi-\frac2\pi\sum_{m=1}^\infty\frac{\cos(2mx)+m\sin(2mx)}{(4m^2-1)(m^2+1)}.}
$$
The differentiated series converges absolutely and uniformly, because its largest coefficient terms are $O(m^{-2})$. This justifies the term-by-term first <derivative> used in substituting into the <differential equation>. Any two solutions differ by $Ce^{-2x}$, proving that the displayed family is the general solution. The computation is an instance of <Fourier response of a first-order linear differential equation>.