Project sin(x) onto orthonormal basis that span ${(1, x, x^2, x^3, x^4, x^5)}$ on domain $[-\pi, \pi]$ I am self-studying LA through Linear Algebra Done Right 2nd ed. I probably made a blatant error somewhere but I have been stuck for a whole day now.
The book gave the answer $0.987862x − 0.155271x^3 + 0.00564312x^5$.
My attempt:
Goal is to project $v = sin(x)$ onto ${(e_1, e_2, e_3, e_4, e_5, e_6)}$ that span ${(1, x, x^2, x^3, x^4, x^5)}$.


*

*Apply Gram-Schmidt procedure to ${(1, x, x^2, x^3, x^4, x^5)}$, ie


$$e_1 = (\frac 1 {\int_{-\pi}^{\pi} 1 dx})^{1/2} = (\frac 1 {2\pi})^{1/2}$$
$$e_2 = \frac {x-<x, e_1>e_1} {|| {x-<x, e_1>e_1} ||} = \frac{x}{||x||} = \frac{x}{\sqrt{\int_{-\pi}^{\pi}{x^2}dx}} = \frac{x}{4.54625}$$
Let's just consider these 2 orthonormal vectors.


*

*Projecting $v = sin(x)$ onto $e_1$ and $e_2$:
$$P_{e_1}v = <v, e_1>e_1 = \frac{1}{2\pi}\int_{-\pi}^{\pi}{sin(x)}dx = 0$$ since sin(x) is odd.
$$P_{e_2}v = <v, e_2>e_2 = \frac{x}{||x||}\int_{-\pi}^{\pi}{\frac{x}{||x||}sin(x)}dx = \frac{2\pi}{\int_{-\pi}^{\pi}{x^2}dx}x = \frac{2\pi}{20.6709}x = 0.3x \neq 0.98x$$


Can anyone point out to me what I did wrong? Thanks.
 A: You cannot project onto an "orthonormal basis", but you can project onto a subspace $V$. In the example at hand $V$ is the space spanned by the (linearly independent) functions $1$, $x$, $\ldots$, $x^5$. Denote the projection onto $V$ by $P_V$. Since $\sin$ is an odd function and we are referring to the symmetric interval $[-\pi,\pi]$ the required projection  $P_V(\sin)$  is a function of the form
$$f(x):=a x+ bx^3+cx^5\ .$$
We now have to determine the coefficients $a$, $b$, $c$. Projecting $\sin$ onto $V$ means that $$g:=\sin-P_V(\sin)=\sin-f$$ is orthogonal to $V$, and this in turn is the case iff $g$ is orthogonal to all spanning vectors of $V$. For the vectors $1$, $x^2$, and $x^4$ this is automatically fulfilled. Therefore three conditions remain, namely
$$\int_{-\pi}^\pi \bigl(\sin x- a x- b x^3- c x^5)\>x^k\ dx=0\qquad \bigl(k\in\{1,3,5\}\bigr)\ .$$
Computing the integrals and solving the resulting linear system for $a$, $b$, $c$ gives the values given in your book.
Note that it was not necessary to orthogonalize the given set of vectors spanning $V$.
