Let $V$ be the vector space of all continuous real-valued functions on $[-1,1]$. For all $f,g \in V$ define the inner product $$\langle f,g \rangle =\int_{-1}^1 f(x)g(x)~\mathrm dx$$
Let $v_1(x)=1$, $v_2(x)=x$, and $v_3(x)=x+x^2$ be functions in $V$.
I want to find the projection of $v_3$ onto the subspace $S=\text{span}\left\{ v_1, v_2 \right\}$.
I believe the answer is $x$, but I am not fully convinced. I see that $v_3$ is the sum of a vector in $S$, namely $x$, and a vector not in $S$, namely $x^2$. However, $x^2 \notin S^\perp$ because for any $a_1+a_2x\in S$ we have $$\langle a_1+a_2x, x^2 \rangle =a_1 \langle 1,x^2\rangle +a_2 \langle x,x^2\rangle=a_1 \int_{-1}^1 x^2~\mathrm dx + a_2 \int_{-1}^1 x^3~\mathrm dx,$$ which will not be equal to zero if $a_1 \neq 0$.
Not sure what to do here...some help?
We may compute the projection as $$ \operatorname{proj}_S(v_3) = \frac{\langle v_1, v_3\rangle}{\langle v_1, v_1\rangle}v_1 + \frac{\langle v_2, v_3\rangle}{\langle v_2, v_2\rangle}v_2 $$
since $v_1$ and $v_2$ are orthogonal. If they were not orthogonal, we would first have to apply the Gram-Schmidt procedure to produce an orthogonal basis of $S$, as in Omnomnomnom's answer, in order to use this formula. Evaluating our desired expressions: \begin{align} \langle v_1, v_3\rangle &= \int_{-1}^1(x + x^2)\,dx = 2/3, \\ \langle v_2, v_3\rangle &= \int_{-1}^1(x^2 + x^3)\,dx = 2/3, \\ \langle v_1, v_1\rangle &= \int_{-1}^1 1\,dx = 2, \\ \langle v_2, v_2\rangle &= \int_{-1}^1 x^2\,dx = 2/3. \end{align} Hence, $$ \operatorname{proj}_S(v_3) = \tfrac{1}{3}v_1 + v_2 = 1/3 + x. $$