Let $f:[0, \pi] \to \mathbb{R}$ with the $L^2$ inner product
$$ \langle f,g \rangle = \int_0^{\pi} f(x)g(x) \mathrm{d}x $$
I want to find a projection of $f(x)=1$ onto $\sin(x)$ and $\sin(3x)$ and use that to find a function of the form $1+k_1\sin(x)+k_3\sin(3x)$ that is orthogonal to $\sin(x), \sin(2x), \sin(3x), \sin(4x)$.
My work:
I calculate the projection (is this correct?):
$$ Pr_{\sin(x),\sin(3x)}(1)=\frac{\langle 1, \sin(x) \rangle}{\mid \mid \sin(x) \mid \mid^2}\sin(x)+\frac{\langle 1, \sin(3x) \rangle}{\mid \mid \sin(3x) \mid \mid^2}\sin(3x) \\ = \int_0^{\pi} 1\cdot\sin(x)dx\cdot\frac{1}{(\int_0^{\pi}\sin(x)\sin(x)dx)^2}\sin(x) + \int_0^{\pi} 1\cdot\sin(3x)dx\cdot\frac{1}{(\int_0^{\pi}\sin(3x)\sin(3x)dx)^2}\sin(3x) \\ =\frac{8}{\pi^2}\sin(x)+\frac{8}{3\pi^2}\sin(3x) $$
Now I have the function $\frac{8}{\pi^2}\sin(x)+\frac{8}{3\pi^2}\sin(3x)$, but how do I use that to find a function of the form $1+k_1\sin(x)+k_3\sin(3x)$ that is orthogonal to $\sin(x), \sin(2x), \sin(3x), \sin(4x)$?
I am unsure of how to proceed.
First of all, $\cos(m+n)=\cos m\cos n-\sin m\sin n$ and $\cos(m-n)=\cos m \cos n+\sin m \sin n$ so when you subtract these, you find $$ \cos(m-n)-\cos(m+n)=2\sin m \sin n . $$ As a result, $$ \int_0^\pi \sin x \sin 3x \, dx =\frac{1}{2}\int_0^\pi \cos 2x-\cos4x\,dx=0 $$ so $\sin x \perp \sin 3x$. This result holds for any $m\neq n$ actually. Now the key is that since these two are orthogonal, the function $$ 1-Proj_{\sin x} 1 - Proj_{\sin 3x} 1 $$ will be orthogonal to $\sin x$ and $\sin 3x$. It's then easy to verify the rest of the orthogonality.
This is essentially the Gram-Schmidt method from scratch.