Proof
(Prerequisite proofs and exact reading routes)
Proof of the finite real matrix product laws
The complete proof is in 2.1.
Real inner products, their norms and the needed inequalities
The complete proof is in 6.1. These are real positive-definite inner products; no complex bilinear convention is assumed.
Finite basis existence and extension, without a counting assumption
The complete proof is in 3.5. The proof applies to finite-dimensional real vector spaces, including the zero space and empty bases.
Orthonormal bases and extension while retaining prescribed vectors
The complete proof is in 6.2.
Preparation and learning goals
Take to be integers; the rank may still be zero.
We assume real vectors, dot products, Euclidean norms, matrix multiplication and transposes, elimination, column spaces, null spaces, and bases. For , the dot product is and the norm is . A list is orthonormal if is one when and zero otherwise. All calculations in this chapter are exact unless explicitly described otherwise.
Gram–Schmidt does more than turn two vectors into a perpendicular pair. It builds a basis while preserving successive spans; its coefficients organize into a matrix factorization; and that factorization separates a least-squares problem into a perpendicular residual and a triangular system. We develop the whole chain, including what happens when a column is dependent or when every column is zero.
The goals are to construct and check a thin QR factorization, recognize an orthogonal projection from its matrix, solve least-squares problems without confusing fitted vectors with coefficients, and determine what remains identifiable when a model has dependent columns.
1. Span-preserving Gram–Schmidt, with dependence handled honestly
Let be the columns of . Suppose are an orthonormal basis for the span of the columns processed so far. For the next column , form
Taking its dot product with a previous gives
There are two possibilities. If , append . If , append nothing: the new column is already a combination of previous directions. In particular, never divide a zero residual by its norm. Begin with the empty list, for which the sum is zero.
The procedure preserves the required span by induction. In the nonzero case, is a combination of and old basis vectors, so the new belongs to the enlarged column span. Conversely,
so the new column belongs to the new basis span. In the zero case the displayed projection sum already equals , and the span does not change. The new vectors remain orthonormal by the dot-product calculation and normalization. This proves both the construction and its span claim, rather than inferring either from a picture.
After all columns have been processed, the final list has length . If collects these columns, then and
Indeed every column of lies in the span of and its orthonormal coordinates are its dot products with the . The matrix is . With dependent columns, it need not be square or an ordinary triangular matrix.
If , the rank is zero, has no columns, and the projection onto its column space is the zero matrix. This edge case can be understood directly without performing any empty-matrix multiplication.
Quick check
(Run the rank-aware procedure on , , in that order. Which column is skipped, what is the rank, and what are and ?)
Compute each residual exactly and append a direction only when the residual is nonzero.
Solution · Answer
The first column gives . For the second, and , so . For the third, and , so : the third column is skipped. The rank is , , and
Multiplying returns the columns , and , so as the procedure promises.
Exact dependence versus numerical decisions
For exact rational or symbolic data, is a mathematical equality. In floating-point arithmetic, a very small computed residual can result from either near dependence or rounding. Choosing a numerical tolerance requires a scale and an error model; this chapter does not turn the instruction “skip a zero vector” into an unsupported numerical threshold. Changing the column order can change the orthonormal basis, but not the column space being represented.
Worked example 6.5.1
(A rounding trace can lose orthogonality)
A small rounding illustration makes the distinction concrete. Take and . In exact arithmetic the columns are independent, and the second normalized direction is . In a deliberately simplified three-significant-digit calculation, store the first normalized vector as . The stored vector is not exactly unit: . Its dot product with is , rounded to . Round each component of to ; subtracting gives the computed residual , hence the computed normalized direction . Its dot product with the stored first vector is , far from zero.
This is an explicitly specified toy rounding sequence, not a prediction for every machine or implementation. The nearly equal numbers in the subtraction lose information relative to the small true residual; normalization then magnifies its directional error. Exact orthogonality and a correct algebraic certificate do not prevent this loss. Conversely, this example alone proves no general numerical stability theorem and gives no error bound for another algorithm. Assessing a practical implementation requires its arithmetic, scaling and error analysis; no numerical rank threshold is prescribed here.
The triangular inverse used in QR uniqueness
Let be an integer and let be a real upper triangular matrix with every . For any , solve from the last row upwards by
At each step all terms on the right are already known, so the formula gives a solution and proves uniqueness by the same descending induction. Thus is invertible. To obtain column of , take . The recursion first gives for every , then . Therefore is upper triangular with diagonal entries ; in particular these entries are positive when those of are positive.
If are upper triangular, for the product entry vanishes: a nonzero term would require both and . For , only can contribute, so . Hence is upper triangular with positive diagonal whenever have positive diagonal. This is precisely the triangular-matrix step used in the uniqueness proof of positive-diagonal thin QR in §2.
2. From independent columns to thin QR
Now assume the columns are independent. Then , no residual is zero, and the construction produces orthonormal columns. Set
The span identity for column becomes . Collecting columns gives
where is and is an upper triangular matrix with positive diagonal. This is a thin QR factorization. The word thin refers to keeping only the orthonormal directions needed for the column space; when , is not square. Multiplying by shows .
Conversely, if such a factorization has invertible , then implies , hence . Thus has independent columns. A thin factorization with invertible square cannot simply be assumed for a rank-deficient matrix.
The positive diagonal also removes sign ambiguity. In fact this thin QR factorization is unique for a fixed ordered independent column list. Suppose and both diagonals are positive. Then
The matrix is upper triangular with positive diagonal, and . An upper triangular orthogonal matrix with positive diagonal is : its first column has only its first entry nonzero, so unit length makes that entry one; orthogonality with the remaining columns then makes the rest of the first row zero. Repeat on the remaining lower-right block. Therefore , proving and . Without the positive-diagonal convention, changing signs in matching columns and rows gives other valid factorizations.
3. A complete three-column calculation
Worked example 1. Let
The last three rows show immediately that the columns are independent. For the first column,
For the second, , and
Its norm is , giving and .
For the third column, and . Subtract both perpendicular components:
Thus and
The resulting triangular factor is
For an independent check, the unnormalized directions , , and have pairwise dot products zero and squared norms . Hence . Also the three identities used to construct the columns give . Both identities should be checked: orthonormal columns alone do not establish a factorization of the particular input matrix.
4. Projection as a linear map
For any matrix with orthonormal columns, define
For , the vector belongs to the column space. Its residual satisfies , so it is perpendicular to every vector in that space. If is any other vector in the space, then belongs to it and is orthogonal to . Therefore
The unique nearest vector is . Uniqueness follows because the second term is zero exactly at . This proves the projection formula and its minimum-distance property together.
The matrix has two identities:
Its image is , since every output lies there and it fixes every . Its kernel is , since is equivalent to . Thus decomposes into a part in the subspace and a perpendicular part, and projects onto the latter.
Worked example 6.5.2
(The projector onto one line, and the Pythagorean check)
Let . Since , the one-column matrix has orthonormal columns, and the projector of this section is
It is visibly symmetric, and . Its trace is , the dimension of the line it projects onto.
Project . Here , so
The residual is perpendicular to the line: . The distance identity of this section then gives the distance from to the line as . As a final check, , the Pythagorean form of the decomposition .
Counterexample mode
Orthonormal columns do not make $QQ^T$ the identity
The identity says only that the columns of are orthonormal; it makes a left inverse of , not a right inverse. Take the single orthonormal column in . Then , but
it is the projector of this section onto the horizontal axis, and it sends to zero. In general holds exactly when . If , then is square with , so and ; if , the product has rank at most . For the thin factorization of §2 with , is therefore the projection onto the column space, and is exactly the part of that no coefficient vector can fit.
These identities also characterize orthogonal projections. If a real square matrix satisfies and , then belongs to its image and, for any image vector ,
So the residual is perpendicular to the image, and the preceding distance identity applies. Idempotence alone is insufficient: has , but maps to , whereas its image is the horizontal axis and the closest point to on that axis is zero. This projection is oblique, not orthogonal.
For the four-dimensional example in §3, is perpendicular to all three columns of . Since the column space has dimension three, it equals the hyperplane . The same orthogonal projector can be written
The equality follows because both maps keep the component in that hyperplane and remove the component along its normal. It can also be verified by direct multiplication.
Quick check
(Is an orthogonal projector? If so, onto which subspace, and what are and the residual for ?)
Test the two identities of this section, then write as .
Solution · Answer
Yes. The matrix is symmetric, and each entry of is , so . With we have , so projects onto the line . For , and the residual is , which is perpendicular to .
5. Least squares, proved without assuming uniqueness
Given and , a least-squares coefficient vector minimizes over all . If is inconsistent, this is an approximation criterion, not a newly discovered exact solution.
A coefficient vector minimizes the error exactly when its residual is perpendicular to the column space. For necessity, fix any . The error at is
If , then . Choosing strictly reduces the error, contradicting minimality. Thus for every . For sufficiency, that condition makes the cross term zero for every , so
In matrix notation, the perpendicularity condition is
These are the normal equations. They are necessary and sufficient regardless of column independence. Independence is needed for uniqueness of the coefficients, not for the characterization itself.
Proof X-ray
One direction is tested at a time
The characterization of minimizers never compares with all coefficient vectors at once. Necessity fixes one direction and studies the one-variable quadratic : a nonzero cross term means this quadratic is not smallest at , and the chosen lowers the error by . Sufficiency uses the same expansion with the cross term removed, leaving . Neither step uses independence of the columns. Independence enters only afterwards, when the null space decides whether the minimizer is unique, and existence comes from a different source altogether, the projection of §4.
Existence follows from projection. Construct an orthonormal basis of the column space by the rank-aware procedure. The projected vector lies in that column space, so by its definition there is at least one with . That vector is a minimizer. The fitted vector is unique, and if one minimizer is , then all minimizers are exactly
Indeed adding a null vector does not change the fit. Conversely all minimizing coefficients give the same unique nearest fitted vector, so their differences lie in the null space. Coefficients are unique exactly when , equivalently the columns are independent. These statements include the zero matrix: its fitted vector is zero and every coefficient vector minimizes the fixed error .
Quick check
(For the one-column matrix and , find the least-squares coefficient, the fitted vector and the residual.)
Use the normal equations, then check the residual against the column.
Solution · Answer
The normal equation is , that is, , so : the mean of the entries of . The fitted vector is and the residual is . Its dot product with the column is , and the minimum squared error is . The coefficient is unique because the single nonzero column is independent.
6. Least squares through a triangular system
For independent columns, use from §2. Decompose into . The second part is perpendicular to every column of , while is a vector of column-space coordinates. Therefore
We used for the second term. The first term does not depend on . Since is invertible, the second is uniquely minimized at zero, giving
Solve this upper triangular system by back substitution. The fitted vector is and the squared residual is the first term. This is the same answer as the normal equations: substituting gives , and the invertibility of makes the systems equivalent. The QR derivation avoids having to form to establish the answer.
Worked example 2. Use the matrix from §3 with . The orthonormal-coordinate right side is
The last triangular equation gives . The second gives
hence . The first then gives . Thus
The residual is . Its dot product with each original column is zero and . Independently, for the normal from §4, giving , exactly the same residual. The agreement checks both the triangular arithmetic and the geometry.
Worked example 6.5.3
(Orthogonal columns decouple the coefficients)
Let
The columns and are already orthogonal, and each has norm . Gram–Schmidt therefore subtracts nothing: , so
The right side of the triangular system is
so . Because is diagonal, each coefficient is the projection coefficient onto its own column, , computed without reference to the other column. The fitted vector and residual are
Both checks of this section hold: and . The normal equations agree, since and . Finally, , and the minimum squared error is .
Rank-deficient coefficients
Worked example 3. Let
The second column is twice the first, so Gram–Schmidt skips it. From the first and third columns it constructs
Here
To attain the projected vector, solve . The second equation gives , and the first reduces to . All minimizers are
They all give and residual , with squared norm three. The normal vector is perpendicular to every original column, independently confirming the fit. There is one fitted vector but a line of coefficient vectors. Among those, the coefficient norm is and is smallest at ; choosing a smallest-norm coefficient is an additional selection rule, not a consequence of least-squares uniqueness.
7. Centering a straight-line fit is Gram–Schmidt
Fit a line to data pairs by minimizing equal squared residuals. Let , , and . Define
Gram–Schmidt starts with . Removing from its projection onto gives . If , then
Back substitution in yields
Subtracting in the numerator does not change it because . The formula therefore follows from orthogonalization, not from memorizing a separate statistical identity. Its residuals sum to zero and their dot product with is zero, exactly the two normal-equation checks.
If , all equal a constant . The two model columns are dependent, and no data distinguish from separately. The best fitted constant is and all coefficient pairs satisfying minimize the error. Dividing by would erase this meaningful case.
Worked example 4. For , we have , , , and the centered cross-product is six. Therefore , . The fitted values are and residuals are . Their sum and their dot product with both vanish. The squared error is .
Equal squared errors are part of this model. Rescaling one observation's error or assigning weights changes the optimization criterion. No probabilistic assumption about measurement noise is needed to derive these exact algebraic least-squares formulas.
8. Exercises
- Apply Gram–Schmidt to , . Give a thin QR factorization of the matrix with these columns and check both and .
- Run the rank-aware procedure on in that order. Which column is skipped? Give and .
- Explain why an matrix with cannot have a thin QR factorization with orthonormal columns. How many nonzero directions can the rank-aware procedure produce?
- Find the orthogonal projection of onto the plane , its residual, and the distance to the plane.
- Show that is an orthogonal projector. Find its image, kernel, and rank without row-reducing it.
- For the matrix in Exercise 1 and , solve least squares through its triangular factor. Check the residual against the original columns and give the minimum squared error.
- For and , find every least-squares coefficient, the unique fitted vector, and the residual. Among the minimizers, find the one of smallest coefficient norm.
- Fit a least-squares line to using centered sums. Give the residual and verify both normal-equation checks.
- All three observation inputs equal three, and their outputs are . Find every least-squares line coefficient pair, the fitted values, and the minimum squared error. Explain the failure of a unique slope.
- Verify for . Find a vector for which is not the nearest point in . Which identity of an orthogonal projector fails?
- Suppose and have orthonormal columns and the same column space. Prove that . Explain why a change of orthonormal basis cannot change the fitted vector.
- Let be the zero matrix and . State all least-squares coefficients, the normal equations, the fitted vector, and the minimum squared error. Does existence of a least-squares solution require a nonzero rank?
9. Complete solutions
1. The first vector has norm , so . Its dot product with is . Subtracting the projection gives
Thus and
The unnormalized directions have dot product and squared norms two and six, so . The first reconstructed column is . The second is . Hence .
2. Start with . The second column has coordinate along and residual zero, so it is skipped. The third column is already a unit vector perpendicular to , giving . Thus
Direct multiplication gives the three original columns. The rank is two; skipping a column preserves its information as a column of , rather than deleting that column from the model.
3. Orthonormal vectors are independent: dotting a relation with each vector makes its coefficient zero. An independent list in has at most elements. Thus forbids orthonormal columns. The rank-aware procedure produces exactly nonzero directions; additional columns must have zero residual once the span can no longer increase.
4. The normal is , with and . The perpendicular residual is and the projection is
Its coordinates sum to zero, so it lies in the plane. The residual is parallel to the normal and hence perpendicular to the plane, proving it is the correct projection. The distance is .
5. Writing gives . The rank-one matrix is symmetric and satisfies . Therefore and . It removes the normal component and fixes every vector whose coordinates sum to zero. Its image is the two-dimensional plane , its kernel is , and its rank is two. This is the same geometric subspace as Exercise 4.
6. From Exercise 1,
The last triangular equation gives . The first gives , so . Thus the fitted vector is and the residual is . Its dot products with and both vanish. The squared residual is three. Independent columns imply this coefficient pair is unique.
7. Every fitted vector has the form , with . Projection onto this line gives
Thus all coefficients are . Their common fitted vector is , and the residual is , perpendicular to both columns. The minimum squared error is . To choose a smallest coefficient norm, complete the square:
The unique smallest-norm choice is , hence . This additional minimization does not change the fitted vector or residual error.
8. Here , , and . The centered cross-product may be calculated as . Thus and . Fitted values are and residuals are . Their sum is zero, and their dot product with is . The minimum squared error is .
9. The model predicts the same value at each observation. The output mean is four. The squared error is
It is minimized exactly when . Hence every pair is a minimizer, the fitted values are , and the minimum squared error is eighteen. All input values are equal, so a slope change can be offset by an intercept change. Algebraically the two design columns are dependent and .
10. Multiplication gives . Its image is the horizontal axis. For , it gives , whose squared distance to is two, whereas the axis point zero has squared distance one. Also . Symmetry, and consequently orthogonality of the residual to the image, fails.
11. For any , let and . Both belong to the common subspace, and both residuals are perpendicular to it. Their difference therefore belongs to the subspace and is also perpendicular to it, by subtracting the residuals. Its dot product with itself is zero, so . Since this holds for every , the two matrices are equal. A least-squares fitted vector is this projection onto the model's column space; changing its orthonormal coordinates cannot change the projection.
12. Every gives , so all coefficient vectors minimize the same squared error. The normal equations are and impose no restriction. The fitted vector is zero, the residual is , and the minimum squared error is . Least squares still has a solution at rank zero; it has no unique coefficients here.
Summary
Gram–Schmidt preserves spans one column at a time and reveals exact dependence through a zero residual. Independent columns give a thin QR factorization with an invertible triangular factor. Orthonormal coordinates produce an orthogonal projector, whose symmetric and idempotent identities express its geometry. Least squares always selects a unique fitted vector, while its coefficients are unique only when the column map is injective. Centering a line fit is one concrete instance of the same construction.