Solution (source code)

= Solution

Multiply the <complex Fourier series> by $e^{-i\omega rt}$ and integrate over one <period>. <Fourier orthogonality> removes every term except the one with index $r$, giving
$$
\boxed{u_r=\frac1T\int_0^Tf(t)e^{-i\omega rt}\,dt.}
$$
For general <square-integrable functions>, this is an <orthogonal projection> onto the corresponding <Fourier mode>. It remains valid when the expansion converges only in <L2 space>: integrate finite <Fourier partial sums> first, then pass to the limit using the <Cauchy-Schwarz inequality>. No unjustified pointwise exchange of an infinite series and an integral is needed.