This is question number 11.10 (b) APostol's Chapter: Fourier series and Fourier integrals.
Prove that $ x= \pi / 2 - 4/ \pi \sum_{n=1}^{\infty} \frac{ \cos(2n-1) x } { (2n-1)^2}$ if $0 \leq x\leq \pi$.
I have proved $a_0/2 = \pi /2$ using $a_0 = 2/ \pi \int_{0}^{\pi} x\, dx$. Also, I proved $b_n=0$. But while proving $4/ \pi \sum_{n=1}^{\infty} \frac{ \cos(2n-1) x } { (2n-1)^2}$ if $0 \leq x\leq \pi$, I am getting $a_n=2/\pi [ (\cos (n\pi) / n^2) -1/n^2]$.
Can you please tell how to obtain what is given?
You have obtained the correct value for $a_n$. Just note that $\cos (n \pi)=(-1)^{n}$ so your answer coincides with the given answer.