The function $f$ is $3$-periodic and $$f(t)=\left\{ \begin{array}{ll} t,\quad &0\leq t\leq1\\ 1,\quad &1<t<2\\ 3-t,\quad &2\leq t \leq 3 \end{array} \right. $$
Expand $f$ as a (real) Fourier series.
Attempt: I simply use the formulae for $a_0,a_n$ and $b_n$. The value of $L$ is $2L=3\Leftrightarrow L=3/2.$ this gives
$$a_0=\frac1{2L}\int\limits_{-L}^Lf(t)\,\mathrm dt=\frac13\cdot2=\frac23,$$ which also is easy to see by drawing $f(t)$. Now
\begin{align} a_n &=\frac23\left[\,\int\limits_{-3/2}^{-1}\cos\left(\frac{2\pi nt}3\right)\,\mathrm dt-\int\limits_{-1}^0t\cos\left(\frac{2\pi nt}3\right)\,\mathrm dt+\int\limits_0^1t\cos\left(\frac{2\pi nt}3\right)\,\mathrm dt+\int\limits_1^{3/2}\cos\left(\frac{2\pi nt}3\right)\,\mathrm dt\,\right]\\ &=\frac{\sin(\pi n)-\sin\left(\frac{2\pi n}{3}\right)}{\pi n}, \end{align}
since the two middle integrals cancel and the two outer are the same. For $b_n$ I have, with identical integrals as above but replacing $\cos$ by $\sin$, that $b_n=0$. This means that
\begin{align} f(t)&=\frac{2}{3}-\sum_{n=1}^{\infty}\frac{\sin(\pi n)-\sin\left(\frac{2\pi n}{3}\right)}{\pi n}\cos\left(\frac{2\pi nt}{3}\right)\\ &=\frac{2}{3}-\frac{2}{\pi}\sum_{n=1}^{\infty}\frac{\sin{\left(\frac{2\pi n}{3}\right)}}{n}\cos\left(\frac{2\pi nt}{3}\right), \end{align}
since $\sin(\pi n)=0 \ \forall \ n\in\mathbb{Z}.$ However the book wants the answer to be
$$f(t)=\frac{2}{3}-\frac{3}{\pi^2}\sum_{n=1}^{\infty}\frac{1-\cos\left(\frac{2\pi n}{3}\right)}{n^2}\cos\left(\frac{2\pi nt}{3}\right).$$
Can someone help me find the mistake?
Hint: What is $f(t)$ for $-1 \le t \le 0$? Is it $f(t)=+t$ or $f(t)=-t$?
Btw, you could evaluate $a_n$ as $$a_n = \frac{2}{T} \int_{0}^{T} f(t) \cos\left(\frac{2\pi}{T}t\right) dt,$$ which could save some of your time in figuring out what $f(t)$ should be for $t<0$.
In response to the comment, $$a_n = \frac{2}{T}\int_{-T/2}^{T/2} f(t)\cos\left(\frac{2\pi}{T}t\right) dt = \frac{2}{T}\int_{-T/2}^{0} f(t)\cos\left(\frac{2\pi}{T}t\right) dt + \frac{2}{T}\int_{0}^{T/2} f(t)\cos\left(\frac{2\pi}{T}t\right) dt.$$ For the first integral, substitute $t = y+T$ to get $$\int_{-T/2}^{0} f(t)\cos\left(\frac{2\pi}{T}t\right) dt = \int_{T/2}^{T} f(y)\cos\left(\frac{2\pi}{T}y\right) dy.$$ Therefore, $$a_n = \frac{2}{T}\int_{0}^{T} f(t)\cos\left(\frac{2\pi}{T}t\right) dt.$$