Find the $L^2[-\pi,\pi]$ projection of $f(x)$ I need to find the $L^2[-\pi,\pi]$ projection of $f(x)=x^2$ onto the space $V_n\subset L^2[-\pi,\pi]$ spanned by
$\left\{\frac{1}{\sqrt{2\pi}},\frac{\sin(jx)}{\sqrt{\pi}},\frac{\cos(jx)}{\sqrt{\pi}};j=1,\dots,n\right\}$
for $n=1$,$n=2$ and $n=3$.
I really want to learn how to do this but I can't get started.
 A: For $n \ge 1$,
$$
    \int_{-\pi}^{\pi}x^{2}\sin(nx)\,dx=0,\;\;\; n =1,2,3,\cdots,N.
$$
And,
$$
\begin{align}
  \int x^{2}\cos(nx)\,dx & = x^{2}\frac{\sin(nx)}{n}-\int 2x\frac{\sin(nx)}{n}\,dx \\
       & = x^{2}\frac{\sin(nx)}{n}+2x\frac{\cos(nx)}{n^{2}}-\int 2\frac{\cos(nx)}{n^{2}}\,dx \\
       & = x^{2}\frac{\sin(nx)}{n}+2x\frac{\cos(nx)}{n^{2}}-2\frac{\sin(nx)}{n^{3}}+C, \\
  \int_{-\pi}^{\pi}x^{2}\cos(nx)\,dx & = \frac{4\pi(-1)^{n}}{n^{2}},\;\;\; n=1,2,3,\cdots,N.
\end{align}
$$
Also,
$$\int_{-\pi}^{\pi}x^{2}\,dx = \frac{2\pi^{3}}{3}.$$
The orthogonal projection $P_{N}x^{2}$ that you want is
$$
    P_{N}x^{2} = \frac{1}{2\pi}\int_{-\pi}^{\pi}x^{2}\,dx
      +\\
   +\sum_{n=1}^{N}\left[\frac{1}{\pi}\int_{-\pi}^{\pi}t^{2}\sin(nt)\,dt\right]\sin(nx)+
       \left[\frac{1}{\pi}\int_{-\pi}^{\pi}t^{2}\cos(nt)\,dt\right]\cos(nx) \\
   = \frac{\pi^{2}}{3}+\sum_{n=1}^{N}\frac{4(-1)^{n}}{n^{2}}\cos(nx).
$$
The orthogonal projection onto the first terms up to $n=N$ is just the truncated Fourier series. It's easy to check that $(x^{2}-P_{N}x^{2}) \perp 1,\cos(nx),\sin(nx)$ for $1 \le n \le N$ from general considerations.
A: In the case $n =1$ you search for a projection $g(x)$ of the form:
$$ g \left( x \right) ={\frac {a}{\sqrt {2\pi }}}+{\frac {b
\sin \left( x \right) }{\sqrt {\pi }}}+{\frac {c\cos \left( x \right) 
}{\sqrt {\pi }}}
$$
The constants $a$, $b$ and $c$ must be determined using that $f(x)-g(x)$ is orthogonal to every vector in $V_{1}$.  Then we have

Solving the equations you obtain

