Understanding the Gram-Schmidt process I would like to better understand the gram-schmidt process. The statement of the theorem in my textbook is the following:

The Gram-Schmidt sequence $[u_1, u_2,\ldots]$ has the property that $\{u_1, u_2,\ldots, u_n\}$ is an orthonormal base for the linear span of $\{x_1, x_2, \ldots, x_k\}$ for $k\geq 1$. The formula for $\{u_1, u_2,\ldots, u_n\}$ is:
  \begin{equation}
x_k   = \left|\left| x_k - \sum\limits_{i<k}\langle x_k, u_i\rangle u_i \right|\right|_2^{-1} \left(x_k - \sum\limits_{i<k}\langle x_k, u_i\rangle u_i\right)
\end{equation}

Note that I am primarily interested in how all of the vectors are orthogonal. The norm term in the above equation tells me that all the vectors will be unit vectors and hence we get an orthonormal set. Anyway, I see how this works algebraically; Let $v = x_k - \sum\limits_{i<k}\langle x_k, u_i\rangle u_i$. Now, take the dot product of $\langle v, u_j\rangle$ for some $j<k$:
\begin{equation}
  \langle v, u_j\rangle = \langle x_k, u_j\rangle - \sum\limits_{i<k}\langle x_k, u_i\rangle\langle u_i, u_j\rangle
\end{equation}
When we assume in the induction hypothesis that we have an orthonormal basis for $i<k$ then the sum is zero except when $i=j$. This leaves us with:
\begin{equation}
  \langle v, u_j\rangle = \langle x_k, u_j\rangle - \langle x_k, u_j\rangle = 0
\end{equation}
OK, I can logically follow algebra, but how can I see this geometrically? Can someone provide both 2D and 3D examples/plots? Since I am specifically interested in seeing how all the vectors meet at 90 degrees.
 A: The geometric picture from Gram-Schmidt is this:  
You start with a basis.  Take the first vector.  Scale it so that it's a unit vector.  Good start.  Take the second vector.  If it's orthogonal to the first vector, great.  otherwise, subtract off a multiple of the first vector until it is.  Then scale it so that it's a unit vector.  Moving on, take the third vector.  Subtract off enough of the first vector from it so that it's orthogonal to the first vector now.  Then subtract off enough of the second vector so it's orthogonal to that one, too.  Now scale it so that it's a unit vector.  Keep going like this, by taking the next vector and subtracting of bits of the previous vectors so that it's orthogonal to all of them, and then rescale so that it's a unit vector.  The "bit" that you have to subtract off is the projection of the vector you're currently working on onto the unit vector, and the formula for that is given by the dot product.  
You might find this animation helpful, but I actually found it a little difficult to follow.  http://www.youtube.com/watch?v=pIy8xqh9sWs
A: Consider the following diagram, courtesy of mathinsight.org:

You can think of $(a \cdot u) u$ as the piece of $a$ that is in the direction of $u$. The part that is left over, $a - (a \cdot u) u$, must naturally be the missing side of the triangle, and hence is perpendicular to $u$. So at each step of the Gram-Schmidt process, the formula
$$ v_{n+1} = a - \sum_{j=1}^n \langle a, u_j \rangle u_j, \quad u_{n+1} = v_{n+1}/ \|v_{n+1} \|$$
does the following: it first subtracts all the pieces of $a$ that are in the same direction as all the $u_j$, then it renormalizes. The resulting vector must be orthogonal to all the $u_j$'s since you just subtracted out all the pieces that were not perpendicular.
A: Let $S_{j}$ be the space spanned by $\{\mathbf{x}_{1},\ldots,\mathbf{x}_{j}\}$.
We use an inductive approach, and assume that $\{\mathbf{u}_{1},\ldots,\mathbf{u}_{j}\}$ is an orthonormal basis for $S_{j}$, with the goal of proving that $\{\mathbf{u}_{1},\ldots,\mathbf{u}_{j+1}\}$ is an orthonormal basis for the space $S_{j+1}$.
The method is easiest to understand geometrically if you think in terms of projections.  Let $P_{j}$ be the orthogonal projection onto $S_{j}$.
The main insight is that $$P_{j}\mathbf{x}_{j+1}=\sum_{i\leq j}\langle \mathbf{x}_{j},\mathbf{u}_{i}\rangle\mathbf{u}_{i}$$
so that this sum is the decomposition of $P_{j}\mathbf{x}_{j+1}$ into the orthonormal basis for $S_{j}$. Furthermore, the vector $\left(\mathbf{x}_{j+1}-P_{j}\mathbf{x}_{j+1}\right)$ is the error term associated with this projection, and as such is orthogonal to each of the $\mathbf{u_{i}}$s in $S_{j}$.  It follows that $\left\{\mathbf{u}_{1},\ldots, \mathbf{u}_{j},\left(\mathbf{x}_{j+1}-P_{j}\mathbf{x}_{j+1}\right)\right\}$ is an orthogonal basis for $S_{j+1}$.  All that remains to generate our orthonormal basis is to divide $\left(\mathbf{x}_{j+1}-P_{j}\mathbf{x}_{j+1}\right)$ by its length.  This normalized vector is our $\mathbf{u}_{j+1}$.
A: Question has already been answered, but I just want to make an important point. Gram-Schmidt uses the fact that if you want to project a vector $v$ onto the span of two other vectors $a_1, a_2$, then you just add the projections of $v$ on each of these vectors independently. That is,
$$\text{proj}_{\text{span}(a_1, a_2)} v = \text{proj}_{a_1}v + \text{proj}_{a_2}v$$
BE CAREFUL!!! This formula only works of $a_1, a_2$ are already orthogonal to each other.
To see why this formula fails if they're not, consider $a_1 = (0, 1000, 0)$, $a_2 = (1, 1000, 0)$ and $v = (0, 1000, 50)$. Then
$$\text{proj}_{\text{span}(a_1, a_2)} v = (0, 1000, 0).$$
But
$$\text{proj}_{a_1}v = (0, 1000, 0)$$
and
$$\text{proj}_{a_2}v \approx (0, 1000, 0)$$
so adding these would give
$$\text{proj}_{\text{span}(a_1, a_2)} v \approx (0, 2000, 0).$$
which is wrong.
