Linear algebra · column space
Orthonormal Basis for the Range (Column Space) of a Matrix
The range of a matrix A, also called its column space, is the set of all vectors of the form Ax. A basis for the range is a minimal set of vectors that spans it, and an orthonormal basis is one whose members are mutually perpendicular and have length 1. The number of vectors is the rank of A. Orthonormal bases are preferred in computation because projections onto them are simple dot products and rounding errors do not grow.
Why not use the columns directly
The columns of A span the range, but they may be redundant: if one column is a combination of the others, it adds nothing. Even when the columns are independent, they may point in nearly the same direction, which makes any calculation with them unstable. An orthonormal basis removes both problems. It keeps only as many vectors as the rank, and each is perpendicular to the rest.
Gram-Schmidt on a small example
Let A have columns c₁ = (1, 1, 1), c₂ = (2, 2, 0) and c₃ = c₁ + c₂ = (3, 3, 1). So A = [1 2 3; 1 2 3; 1 0 1].
Step 1: normalize c₁. Its length is √3, so q₁ = (1, 1, 1)/√3.
Step 2: remove from c₂ its component along q₁. The dot product q₁ · c₂ is 4/√3, so the component is (4/3)(1, 1, 1). The remainder is (2 − 4/3, 2 − 4/3, 0 − 4/3) = (2/3, 2/3, −4/3). Its length is √(4/9 + 4/9 + 16/9) = √(24/9) = 2√6/3. Dividing gives q₂ = (1, 1, −2)/√6.
Step 3: c₃ = c₁ + c₂ lies in the span of q₁ and q₂, so subtracting its components along both leaves the zero vector. The process stops. The rank is 2, and {q₁, q₂} is an orthonormal basis for the range.
Verify: q₁ · q₂ = (1 + 1 − 2)/√18 = 0, and q₂ has length √(1 + 1 + 4)/√6 = 1. Also, c₂ = (4/√3)q₁ + (2√6/3)q₂ checks out in the first entry: 4/3 + (2√6/3)(1/√6) = 4/3 + 2/3 = 2.
The numerical methods
Classical Gram-Schmidt loses orthogonality in floating point when columns are nearly dependent. The modified variant is better, and Householder QR, which builds Q from reflections, is better still. Both reveal rank only imperfectly: deciding whether the remainder is “zero” needs a tolerance, and a pivoted QR is needed to make the decision reliable.
The most dependable route is the singular value decomposition A = UΣVᵀ. Count the singular values larger than a tolerance; if that number is r, the first r columns of U form an orthonormal basis for the range. A common tolerance is max(m, n) · σ₁ · ε, where σ₁ is the largest singular value and ε is machine epsilon, about 2.2 × 10⁻¹⁶ in double precision. The remaining columns of U span the orthogonal complement, which is the null space of Aᵀ.
[U, S, V] = svd(A);
s = diag(S);
tol = max(size(A)) * s(1) * eps;
r = sum(s > tol);
Q = U(:, 1:r); % orthonormal basis for range(A)
Using the basis
With Q in hand, the projection of any vector b onto the range is Q(Qᵀb), and the distance from b to the range is the length of b − QQᵀb. That is exactly the residual of a least-squares fit, which is why this page connects to left division and least squares. Testing whether Ax = b has an exact solution amounts to asking whether that distance is zero.
The choice of basis is not unique: any rotation within the span gives another valid answer, and signs of the vectors can flip between software packages. Compare subspaces, not individual vectors.
Related reading includes LU factorization and the glossary entries for range and rank. The linear algebra hub has more.