The Gram-Schmidt Process and QR Factorization
Gram-Schmidt turns any basis into an orthogonal one by repeatedly subtracting off projections onto the span already built. Normalizing the result and recording the coefficients factors the matrix as A = QR, with Q orthonormal and R upper triangular, the factorization behind stable least-squares and eigenvalue algorithms.
╌╌╌╌
An orthogonal basis makes coordinates and projections trivial, but a subspace usually arrives with an arbitrary basis instead. The Gram–Schmidt process converts one into the other: given any basis for a subspace, it produces an orthogonal basis for the same subspace, one vector at a time. Recording the arithmetic as a matrix product yields the QR factorization, the numerically preferred route to least-squares solutions and eigenvalues.
Subtracting the projection
Start with a basis of a subspace . Keep the first vector, . To make the second vector orthogonal to the first, subtract from its projection onto the line :
By the orthogonal decomposition theorem, is the component of orthogonal to , and it stays in because it is a combination of and . Each later vector subtracts its projection onto the span of all the orthogonal vectors already built.
The general process
The span condition is the point of the construction: the orthogonal set built from the first inputs spans exactly the same subspace as those inputs. The proof is induction. Suppose is an orthogonal basis for . Define . By the orthogonal decomposition theorem it is orthogonal to ; it lies in ; and it is nonzero because is not in . So is an orthogonal basis of the -dimensional space .
- 1
- 2for to do
- 3
- 4for to do
- 5remove the component along
- 6return
An orthonormal basis follows by normalizing each at the end. Doing so only after the orthogonal set is complete avoids writing square roots at every step of a hand calculation.
Orthogonalizing a basis
The QR factorization
Apply Gram–Schmidt with normalization to the columns of a matrix. Each original column lies in , so it is a combination of the first orthonormal vectors only. Collecting those combinations as columns records the factorization.
Let be the orthonormal basis from Gram–Schmidt. Because , there are scalars with
and the entries below the diagonal are zero, making upper triangular. Choosing (flip the sign of if needed) makes the diagonal positive. Then for each , so .
Once is known, is a single product. Since ,
so .
Numerical stability of QR
The invertibility of is immediate: if , then , and the independent columns of force . So exists, and and share the same column space.
In floating point, the classical Gram–Schmidt recurrence loses orthogonality: rounding makes the computed drift out of perpendicularity as grows. Reordering the subtractions (the modified Gram–Schmidt variant) helps, but production QR routines instead left-multiply by a sequence of orthogonal reflectors until it becomes upper triangular. That approach parallels the elementary-matrix reduction behind the LU factorization and yields a more accurate ; the details belong to the numerical least-squares lesson.
| Method | Output | Cost | Numerical behavior |
|---|---|---|---|
| Classical Gram–Schmidt | then normalize | low | orthogonality degrades for large |
| Modified Gram–Schmidt | same, reordered updates | low | markedly better, still imperfect |
| Reflector-based QR | about twice | most accurate |
Summary
- Gram–Schmidt converts a basis into an orthogonal basis by subtracting, from each vector, its projection onto the span of the vectors already orthogonalized, preserving the span at every step.
- Normalization at the end gives an orthonormal basis, the columns of .
- QR factorization records the process as a matrix product: has orthonormal columns spanning , and is upper triangular and invertible.
The QR factorization gives a stable route to the least-squares solution of an inconsistent system.1
Footnotes
- Lay, §6.4 — The Gram–Schmidt Process: Theorem 11 (orthogonalization with the span property), the orthonormal variant, and Theorem 12 (the QR factorization with ), including the numerical notes on loss of orthogonality. ↩
╌╌ END ╌╌