The full problem is this:
Let $f:[-\pi,\pi]\rightarrow\mathbb{C}$ be Riemann integrable. Let $\{c_n\}_{n\in\mathbb{Z}}\subset\mathbb{C}$. Prove that if $s_N=\sum_{n=-N}^Nc_ne^{inx}$ converges in $L^2$ to $f(x)$ then $c_n=\frac{1}{2\pi}\int_{-\pi}^\pi f(x)e^{-inx}dx$.
I have no idea where to start on this. Any hint at all would help immensely!
Thank you!
Write an error function as follows:
$$\begin{align}E(c) &= \int_{-\pi}^{\pi} dx \: \left |f(x) - \sum_{n=-N}^N c_n e^{i n x} \right |^2\\ &= \int_{-\pi}^{\pi} dx \: \left (f(x) - \sum_{n=-N}^N c_n e^{i n x} \right ) \left(f^*(x) - \sum_{n=-N}^N c_n^* e^{-i n x} \right )\\ &= \int_{-\pi}^{\pi} dx \: \left (|f(x)|^2 - f(x)\sum_{n=-N}^N c_n^* e^{-i n x} - f^*(x) \sum_{n=-N}^N c_n e^{i n x} + \sum_{n=-N}^N\: \sum_{n'=-N}^N c_n c_n^* e^{i (n-n') x} \right )\end{align}$$
where $c$ is the vector of coefficients $[c_n]_{n=-N}^N$. Note that, when the sum converges to $f$ in an $L^2$ sense, then
$$\lim_{N \rightarrow \infty} E(c) = 0$$
To find a critical coefficient $c_k$ that minimizes $E$, we solve
$$\frac{\partial E}{\partial c_k^*} = 0$$
Doing this, we obtain
$$\sum_{n=-N}^N c_n \int_{-\pi}^{\pi} dx \: e^{i (n-k) x} = \int_{-\pi}^{\pi} dx \: f(x) e^{-i k x}$$
Using the sifting property of the integral on the LHS, we deduce that
$$c_k \cdot 2 \pi = \int_{-\pi}^{\pi} dx \: f(x) e^{-i k x}$$
which is a Fourier coefficient.