In heat and wave problems the function lives on $(0, L)$ only, the length of a rod. We are free to extend it to $(-L, 0)$ any way we like before building a Fourier series. Extending it as an odd function gives a series of sines only; extending it as an even function gives cosines only. Which one to use depends on the boundary conditions.
🔑 Key idea
For $f$ on $(0, L)$, the sine series and its coefficients are $$f \sim \sum_{n=1}^{\infty} b_n\sin\frac{n\pi x}{L},$$ $$b_n = \frac{2}{L}\int_0^{L} f(x)\sin\frac{n\pi x}{L}\,dx.$$ The cosine series and its coefficients are $$f \sim \frac{a_0}{2} + \sum_{n=1}^{\infty} a_n\cos\frac{n\pi x}{L},$$ $$a_n = \frac{2}{L}\int_0^{L} f(x)\cos\frac{n\pi x}{L}\,dx.$$ Convergence: if $f$ is piecewise smooth, the series converges to the extended function where it is continuous and to the average of the one-sided limits at each jump.
💡 Why it works
Let $f_o$ be the odd extension: $f_o(x) = -f(-x)$ for $-L < x < 0$. Then $f_o\cos\frac{n\pi x}{L}$ is odd, so every $a_n = 0$, and $f_o\sin\frac{n\pi x}{L}$ is even, so $b_n = \frac{1}{L}\int_{-L}^{L} = \frac{2}{L}\int_0^{L}$. The even extension works the same way with the roles swapped. The extension matters for convergence: the odd extension of $f$ is continuous at 0 and $L$ only if $f$ is 0 there, so a sine series always converges to 0 at the ends. A cosine series has no such jumps when $f$ is continuous, which is why its coefficients usually shrink faster.
Answer: $x \sim 1$ $- \frac{8}{\pi^{2}}\left(\cos\frac{\pi x}{2} + \frac{1}{9}\cos\frac{3\pi x}{2} + \dots\right)$, with coefficients shrinking like $\frac{1}{n^{2}}$
✏️ Worked example: Where does it converge?
The sine series of $f(x) = x$ on $(0, \pi)$: what does it converge to at $x = \frac{\pi}{2}$, at $x = \pi$, and at $x = 3\pi$?
At $\frac{\pi}{2}$, $f$ is continuous: the sum is $\frac{\pi}{2}$.
At $\pi$, the odd periodic extension jumps from $\pi$ down to $-\pi$: the average is 0.
$3\pi$ is a period ($2\pi$) away from $\pi$.
Answer: $\frac{\pi}{2}$, $0$, and $0$
⚠️ Common mistake
Using $\frac{1}{L}$ for a half-range series. The sine and cosine series on $(0, L)$ use $\frac{2}{L}$ and integrate over $(0, L)$ only, because they come from integrating an even integrand over $(-L, L)$.
The sine series of $f(x) = x$ on $(0, \pi)$ comes from the odd extension, a sawtooth with jumps at $\pm\pi$. The partial sums are pinned to 0 at the ends, and the coefficients shrink only like $\frac{1}{n}$.The cosine series of the same function comes from the even extension, a triangle wave with no jumps. Three terms already look good: the coefficients shrink like $\frac{1}{n^{2}}$.
Practice
Pass with 3 right answers, the last 2 in a row. Each right answer earns 3 XP.