Equating coefficients in a Fourier series Suppose, for example, using Fourier series techniques to solve a differential equation leads to the following:
$a_0 + \sum_{n=1}^{\infty}a_n\sin(nx)+b_n\cos(nx)=4\sin x$
At this point, why can you equate the coefficients of $\cos(nx)$ and $\sin(nx)$ on the two sides the equation. I don't understand why this step works.
With very many thanks,
Froskoy.
 A: Informally you can recover the coefficient by averaging both sides against $\sin mx$: 
$$\frac{1}{\pi}\int_{-\pi}^{\pi}\left( a_0 + \sum_{n=1}^\infty a_n\sin(nx) + b_n\cos(nx)\right)\sin(mx)\, dx =\frac{1}{\pi}\int_{-\pi}^\pi 4\sin x \sin (mx)\, dx, $$
because the left hand side becomes then
$$a_0 \frac{1}{\pi}\int_{-\pi}^\pi\sin(mx)\, dx+ \sum_{n=1}^\infty a_n\frac{1}{\pi}\int_{-\pi}^\pi\sin(nx)\sin(mx)\, dx+b_n\frac{1}{\pi}\int_{-\pi}^\pi\cos(nx)\sin(mx)\, dx =a_m $$
while the left hand side is $4\delta_{1m}$. This procedure, similar to the original reasoning by Fourier, requires the interchange of integral and sum in left hand side, which can be done if the series converges uniformly. However, that request is excessively restrictive: turns out that convergence in $L^2$ sense will suffice. This can be proven by means of Hilbert space methods.
A: What you want is exactly saying that the functions $x \mapsto \cos( nx)$ and $x \mapsto \sin(nx)$ are linearly indepedent. You can actually prove quite more very simply : they form an orthogonal family in $L^2$ (you prove it by checking that $\int \cos(nx) \cos(mx) = 1$ if $n=m$, 0 otherwise) (with suitable bounds of integration and renormalization constants).
