Choosing a Fourier series expansion
Full series, sine series, cosine series, or half-range -- picked by your function's symmetry and domain, not by habit.
Before grinding through the a_n/b_n integrals, check what symmetry the function already has (or could be given, if it's only defined on half an interval) -- the right choice below makes half the coefficients vanish for free.
Function is odd on [-L, L]
Example
Function is even on [-L, L]
Example
No special symmetry -- use the full series
Let f be periodic with period T and let \omega_0 = 2\pi/T. If f has a Fourier series
f(t) \sim \frac{a_0}{2} + \sum_{n=1}^{\infty}\Big(a_n\cos(n\omega_0 t) + b_n\sin(n\omega_0 t)\Big)that may be integrated term by term, then the coefficients are forced to be
a_n = \frac{2}{T}\int_{-T/2}^{T/2} f(t)\cos(n\omega_0 t)\,dt \quad (n \ge 0), \qquad b_n = \frac{2}{T}\int_{-T/2}^{T/2} f(t)\sin(n\omega_0 t)\,dt \quad (n \ge 1).Show proof
The whole argument rests on the orthogonality of \{1, \cos(n\omega_0 t), \sin(n\omega_0 t)\}_{n\ge 1} over one period [-T/2, T/2]: for integers m, n \ge 1, \int_{-T/2}^{T/2}\cos(n\omega_0 t)\cos(m\omega_0 t)\,dt = \begin{cases} T/2 & n=m \\ 0 & n\ne m\end{cases}, \qquad \int_{-T/2}^{T/2}\sin(n\omega_0 t)\sin(m\omega_0 t)\,dt = \begin{cases} T/2 & n=m \\ 0 & n\ne m\end{cases}, and \int_{-T/2}^{T/2}\cos(n\omega_0 t)\sin(m\omega_0 t)\,dt = 0 for every n, m (an odd function integrated over a symmetric interval). Each of these follows from the product-to-sum identities, which turn every integrand into a sum of \cos or \sin of (n\pm m)\omega_0 t, and a full period of any nonzero-frequency sine or cosine integrates to 0.
Fix m \ge 1 and multiply both sides of the series by \cos(m\omega_0 t), then integrate over [-T/2, T/2], exchanging the sum and the integral (justified by the assumed term-by-term integrability): \int_{-T/2}^{T/2} f(t)\cos(m\omega_0 t)\,dt = \frac{a_0}{2}\int_{-T/2}^{T/2}\cos(m\omega_0 t)\,dt + \sum_{n=1}^\infty\Big(a_n\!\int_{-T/2}^{T/2}\!\cos(n\omega_0 t)\cos(m\omega_0 t)\,dt + b_n\!\int_{-T/2}^{T/2}\!\sin(n\omega_0 t)\cos(m\omega_0 t)\,dt\Big). The constant term vanishes (a full period of a nonzero-frequency cosine integrates to 0), every sine-cosine cross term vanishes by orthogonality, and every cosine-cosine term vanishes except n=m, which contributes a_m \cdot T/2. So the right side collapses to a_m T/2, giving a_m = \frac{2}{T}\int_{-T/2}^{T/2} f(t)\cos(m\omega_0 t)\,dt. The same argument with \sin(m\omega_0 t) in place of \cos(m\omega_0 t) isolates b_m the same way, since now every cosine-sine cross term and the constant term vanish, leaving b_m T/2.
For a_0, multiply by 1 instead and integrate: every n \ge 1 term vanishes (a full period of \cos or \sin), leaving \int_{-T/2}^{T/2} f(t)\,dt = \frac{a_0}{2}\cdot T, i.e. a_0 = \frac{2}{T}\int_{-T/2}^{T/2} f(t)\,dt — exactly the general a_n formula evaluated at n=0, since \cos(0) = 1, which is why the constant term is conventionally written a_0/2 rather than a_0.
Only given on [0, L] -- you choose the extension
The same function extended one way gives a sine series, the other way a cosine series -- neither is "more correct," they just converge to different pictures outside [0,L].
Section