The
vector projection of a vector \mathbf v on a nonzero vector \mathbf u is defined as \operatorname{proj}_{\mathbf u} (\mathbf{v}) = \frac{\langle \mathbf{v}, \mathbf{u}\rangle}{\langle \mathbf{u}, \mathbf{u}\rangle} \,\mathbf{u} , where \langle \mathbf{v}, \mathbf{u}\rangle denotes the
dot product of the vectors \mathbf u and \mathbf v. This means that \operatorname{proj}_{\mathbf u} (\mathbf{v}) is the
orthogonal projection of \mathbf v onto the line spanned by \mathbf u. If \mathbf u is the zero vector, then \operatorname{proj}_{\mathbf u} (\mathbf{v}) is defined as the zero vector. Given k nonzero linearly-independent vectors \mathbf{v}_1, \ldots, \mathbf{v}_k the Gram–Schmidt process defines the vectors \mathbf{u}_1, \ldots, \mathbf{u}_k as follows: \begin{align} \mathbf{u}_1 & = \mathbf{v}_1, & \!\mathbf{e}_1 & = \frac{\mathbf{u}_1}{\|\mathbf{u}_1\|} \\ \mathbf{u}_2 & = \mathbf{v}_2-\operatorname{proj}_{\mathbf{u}_1} (\mathbf{v}_2), & \!\mathbf{e}_2 & = \frac{\mathbf{u}_2}{\|\mathbf{u}_2\|} \\ \mathbf{u}_3 & = \mathbf{v}_3-\operatorname{proj}_{\mathbf{u}_1} (\mathbf{v}_3) - \operatorname{proj}_{\mathbf{u}_2} (\mathbf{v}_3), & \!\mathbf{e}_3 & = \frac{\mathbf{u}_3 }{\|\mathbf{u}_3\|} \\ \mathbf{u}_4 & = \mathbf{v}_4-\operatorname{proj}_{\mathbf{u}_1} (\mathbf{v}_4)-\operatorname{proj}_{\mathbf{u}_2} (\mathbf{v}_4)-\operatorname{proj}_{\mathbf{u}_3} (\mathbf{v}_4), & \!\mathbf{e}_4 & = {\mathbf{u}_4 \over \|\mathbf{u}_4\|} \\ & {}\ \ \vdots & & {}\ \ \vdots \\ \mathbf{u}_k & = \mathbf{v}_k - \sum_{j=1}^{k-1}\operatorname{proj}_{\mathbf{u}_j} (\mathbf{v}_k), & \!\mathbf{e}_k & = \frac{\mathbf{u}_k}{\|\mathbf{u}_k\|}. \end{align} The sequence \mathbf{u}_1, \ldots, \mathbf{u}_k is the required system of orthogonal vectors, and the normalized vectors \mathbf{e}_1, \ldots, \mathbf{e}_k form an
orthonormal set. The calculation of the sequence \mathbf{u}_1, \ldots, \mathbf{u}_k is known as
Gram–Schmidt orthogonalization, and the calculation of the sequence \mathbf{e}_1, \ldots, \mathbf{e}_k is known as
Gram–Schmidt orthonormalization. To check that these formulas yield an orthogonal sequence, first compute \langle \mathbf{u}_1, \mathbf{u}_2 \rangle by substituting the above formula for \mathbf{u}_2: we get zero. Then use this to compute \langle \mathbf{u}_1, \mathbf{u}_3 \rangle again by substituting the formula for \mathbf{u}_3: we get zero. For arbitrary k the proof is accomplished by
mathematical induction. Geometrically, this method proceeds as follows: to compute \mathbf{u}_i, it projects \mathbf{v}_i orthogonally onto the subspace U generated by \mathbf{u}_1, \ldots, \mathbf{u}_{i-1}, which is the same as the subspace generated by \mathbf{v}_1, \ldots, \mathbf{v}_{i-1}. The vector \mathbf{u}_i is then defined to be the difference between \mathbf{v}_i and this projection, guaranteed to be orthogonal to all of the vectors in the subspace U. The Gram–Schmidt process also applies to a linearly independent
countably infinite sequence {{math|{
vi}
i}}. The result is an orthogonal (or orthonormal) sequence {{math|{
ui}
i}} such that for natural number : the algebraic span of \mathbf{v}_1, \ldots, \mathbf{v}_{n} is the same as that of \mathbf{u}_1, \ldots, \mathbf{u}_{n}. If the Gram–Schmidt process is applied to a linearly dependent sequence, it outputs the vector on the ith step, assuming that \mathbf{v}_i is a linear combination of \mathbf{v}_1, \ldots, \mathbf{v}_{i-1}. If an orthonormal basis is to be produced, then the algorithm should test for zero vectors in the output and discard them because no multiple of a zero vector can have a length of 1. The number of vectors output by the algorithm will then be the dimension of the space spanned by the original inputs. A variant of the Gram–Schmidt process using
transfinite recursion applied to a (possibly uncountably) infinite sequence of vectors (v_\alpha)_{\alpha yields a set of orthonormal vectors (u_\alpha)_{\alpha with \kappa\leq\lambda such that for any \alpha\leq\lambda, the
completion of the span of \{ u_\beta : \beta is the same as that of {{nowrap|\{ v_\beta : \beta .}} In particular, when applied to a (algebraic) basis of a
Hilbert space (or, more generally, a basis of any dense subspace), it yields a (functional-analytic) orthonormal basis. Note that in the general case often the strict inequality \kappa holds, even if the starting set was linearly independent, and the span of (u_\alpha)_{\alpha need not be a subspace of the span of (v_\alpha)_{\alpha (rather, it's a subspace of its completion). == Example ==