The Gram–Schmidt process is an algorithm in linear algebra that constructs an orthonormal basis from an ordered, linearly independent collection of vectors. It successively subtracts the components of each vector along previously constructed directions, then normalizes the remaining vector. The resulting vectors span the same subspace as the original collection. Applied to matrix columns, the process produces a QR decomposition, connecting its geometric interpretation with computational methods. (github.com)
Mathematical setting
Let be vectors in a vector space over the real numbers or complex numbers, equipped with an inner product. Orthogonality means that the inner product of two vectors is zero; orthonormality additionally requires each vector to have unit length. Gram–Schmidt uses the associated norm,
The construction applies to abstract inner-product spaces, not only coordinate vectors: polynomials and suitable spaces of functions also admit it. (people.tamu.edu)
The standard assumption is linear independence. If the input is a basis of a finite-dimensional space, the output is an orthonormal basis of that space. More generally, it is a basis of the inputs’ linear span, which may be a proper subspace of the ambient space. (github.com)
Classical construction
Use the convention that is conjugate-linear in its first argument and linear in its second. Set
For , define
Each summand is the orthogonal projection of onto the direction . Subtracting their sum leaves the component perpendicular to all previously constructed directions. Omitting normalization gives mutually orthogonal vectors , rather than unit vectors . (archive.nptel.ac.in)
The justification follows directly from the inner-product identities. Assuming the earlier are orthonormal, for every ,
Moreover, each new vector is a linear combination of the first inputs, and the defining equation expresses in terms of the new vectors. Consequently,
Independence ensures , so normalization is possible. (archive.nptel.ac.in)
For dependent inputs, a zero residual identifies a vector already in the span of earlier accepted vectors; it can be discarded. The output generally depends on input order, although the final spanned subspace does not. (people.tamu.edu)
Worked example
Consider, in Euclidean space ,
With the standard dot product, the first normalized vector is
The second residual is
Thus
Direct calculation gives and unit norm for both vectors. This illustrates the general construction: form an orthonormal basis of the plane spanned by the two inputs. (archive.nptel.ac.in)
Matrix formulation and least squares
Place independent vectors in the columns of an matrix , with . Gram–Schmidt yields
where and is upper triangular. Its entries are
The relation uses the conjugate transpose and the identity matrix. For real matrices, . When , is an orthogonal matrix in the real case and a unitary matrix in the complex case. (github.com)
For ordinary least squares, minimizing reduces, in exact arithmetic, to solving
The fitted vector is . This avoids explicitly forming the normal equations , an important distinction in numerical computation. (ocw.mit.edu)
Modified Gram–Schmidt and numerical behavior
In floating-point arithmetic, classical Gram–Schmidt can lose orthogonality, particularly when input vectors are nearly dependent. Modified Gram–Schmidt changes the order of operations: initialize , then successively compute
before normalizing . Each projection therefore uses the updated residual rather than the original vector. The two versions are equivalent in exact arithmetic but differ in numerical stability. (ocw.mit.edu)
Modified Gram–Schmidt generally preserves orthogonality better, but substantial loss can still occur. Reorthogonalization repeats the projection-removal step to reduce remaining components along earlier vectors. Both basic versions require arithmetic operations. Householder transformations provide another QR construction with stronger orthogonality properties in floating-point computation. (netlib.org)
Function spaces and iterative methods
Applying Gram–Schmidt to , using
produces orthogonal polynomials. With conventional scaling, these are the Legendre polynomials, beginning with , , and . Conventional Legendre normalization differs from unit-norm normalization. In a separable Hilbert space, orthogonalizing a countable collection with dense span produces an orthonormal basis in the sense of closed linear span. (people.tamu.edu)
In numerical linear algebra, Gram–Schmidt also builds bases of Krylov subspaces. Orthogonalizing successive matrix-generated vectors underlies the Arnoldi iteration, which supplies the orthonormal basis used by the generalized minimal residual method for solving linear systems. (netlib.org)