I was wondering how we derive these formulas, and why we have a separate formula for $a_0$? All I know from advanced engineering mathematics text book are following formulas but where do they come from?
$$a_0 = \frac{1}{2L} \int_{-L}^{L} f(x) dx,~~~~a_n = \frac{1}{L} \int_{-L}^{L} f(x) \cos{\frac{n\pi x}{L}}dx,~~~~b_n = \frac{1}{L} \int_{-L}^{L} f(x) \sin{\frac{n\pi x}{L}} dx$$
I found the proof somewhere on net!
for some function with some properties we have: $$ \int _0 ^Tf(x)dx = \int_\alpha ^{\alpha + T}f(x)dx $$
and now we have(suppose that $L = \pi$): $$ f(x) = a_0 + \sum _{n=1}^{\infty}(a_n\cos(nx) + b_n\sin(nx)) $$
If we Integrate from $[-\pi, \pi]$ from above we have: $$ \int_{-\pi}^{\pi}f(x)dx = \int_{-\pi}^{\pi}a_0 + \sum _{n=1}^{\infty}\int_{-\pi}^{\pi}(a_n\cos(nx) + b_n\sin(nx)) $$ the sum goes to zero and finally we have: $$ \int_{-\pi}^{\pi}f(x)dx = 2\pi a_0 $$
for $a_n$ we multiply the general form with $\cos(nx)$ for $b_n$, $\sin(nx)$ comes to play, this method is due to Euler and is named Euler formulas, And also fourier him self did it this way!
copper.hat's comment is really an answer. If you want to represent a function of period $2L$ in terms of the functions $ x \mapsto 1 $, $ x \mapsto \cos \left( \frac {n\pi x}{L} \right), x \mapsto \sin \left( \frac {n \pi x}{l} \right) $, then the coefficients are given by the above.