Most of your work is correct. You just need to organize your calculations.
You write
an when you actually are calculating
a0. You write
bn when you are calculating
an and in the same time you write
bn when you are calculating
bn.
You calculated
an as
+n2π24 when it should be
−n2π24 for
n=1,3,5,⋯
You say
a0=1 which is correct. You write:
f(x)=2a0+⋯→ correct, then you write:
f(x)=1+⋯→ wrong.
You should write:
f(x)=21+⋯
Now you know the values of
a0,an, and
bn. Write the general form as:
f(x)=2a0+n=1∑∞ancos2nπx+bnsin2nπx
Since
an takes only odd indices, you can change any
n there to
2n−1. Now replace the coefficients with their values.
f(x)=21+n=1∑∞−(2n−1)2π24cos2(2n−1)πx+(−1)nnπ2sin2nπx
Now the second term will keep track of the odd indices while the third term will keep track of both odd and even as
bn takes both.