Fitting a line to measured points is a least-squares problem, and two textbook routes solve it, the normal equations and a QR factorization of . When the columns of are independent they give the same answer in exact arithmetic, but rounded arithmetic can separate them. The columns and are independent for every , yet for their Gram matrix becomes singular once its entries are rounded to six significant digits. This lesson explains that loss with the condition number of a rectangular matrix and turns it into a choice between QR, Cholesky, pivoted elimination and the SVD, made from the structure and the rank of the problem.
Key terms
Condition number of a rectangular matrix
Definition Let , where is or , have full column rank, , which forces . Then all singular values are positive, , the square matrix is invertible, and the pseudoinverse is . It satisfies , and its singular values are , so . The two-norm condition number of is
For a nonsingular square matrix the pseudoinverse is , and this is the condition number of the earlier lessons. Because , the extreme singular values are the largest and the smallest stretch of , that is and over unit vectors , so . For a right-hand side in the column space, a change moves the least-squares solution by . Since and ,
For a general the sensitivity of the least-squares solution also depends on the angle between and the column space, and when itself is perturbed and the residual is not small it can involve . So measures the directional scaling of , not every error bound for every data set. The full-column-rank hypothesis is part of the definition. Dividing by the smallest positive singular value of a rank-deficient matrix describes a different problem, and an arbitrarily small change of can raise its rank and make jump. Here and below a tuple such as stands for a column vector.
In plain words A tall matrix with independent columns can stretch some directions more than others. Its condition number is the ratio of the largest stretch to the smallest, and for consistent data it bounds how much a relative change in can be magnified in the solution.
Example Take
The eigenvalues of are and , so the singular values of are and , and . The pseudoinverse is
and multiplying gives , with . A change of rank behaves very differently. The matrix with columns and has for , which grows without bound as . At the rank drops to and the norm of the pseudoinverse falls back to , so an arbitrarily small change in the data moves between and .
Conditioning of the Gram matrix
Definition Let have full column rank, where is or , and let its columns be . The Gram matrix has entries . It is Hermitian positive definite, since for . Its eigenvalues, which are also its singular values, are , and
For the proof take a thin SVD , where has orthonormal columns, and is unitary. Since ,
which is a unitary diagonalization with positive diagonal entries and therefore also an SVD of . The ratio of its extreme singular values is . The identity is exact and concerns the matrix of the normal equations. It does not claim that every normal-equations computation loses exactly twice as many digits as a QR computation. It says that the system being solved has condition number , which exceeds whenever , and in floating point the entries of are also rounded before any solve begins.
In plain words Multiplying on the left by its conjugate transpose squares every stretch. A condition number of for becomes for , and small features of the columns can vanish when the products are rounded.
Example Take and the columns and . Their inner products are , and , so the exact Gram matrix and its determinant are
Now carry out one precisely stated rounding step. Compute the entries exactly, then round each one once to six significant digits. The entry becomes , so every rounded entry equals and the rounded Gram matrix is singular. The columns survive the same rounding, since is stored as , which still differs from . The information was lost when the small quantity was added to a number of size . In terms of conditioning, the matrix has , so . This isolates one mechanism with exact arithmetic and an explicit rounding rule. It is not a measured comparison of two complete solvers.
Normal equations
Definition Let and , where is or . A vector minimizes if and only if the residual is orthogonal to every column of , that is , or
These are the normal equations. They always have a solution, because the orthogonal projection of onto the column space has the form . If , then for every the vectors and are orthogonal, and Pythagoras gives
So is a minimizer, and is another minimizer exactly when , in which case also solves the normal equations. If has full column rank, then is Hermitian positive definite and the least-squares solution is unique. The normal equations are mathematically exact. Their numerical price is that they replace by a matrix with condition number and round the entries of and along the way.
In plain words The best fit leaves an error that is perpendicular to everything the columns can produce. Writing that perpendicularity once for each column gives a small square system in the same unknowns.
Example Fit a line to the points . Here
and the normal equations are
Subtracting the first equation from the second gives , so , and then gives . The fitted values are , the residual is and . As a check, the two entries of are and .
Cholesky solve
Definition Let be Hermitian positive definite, where is or . For this means that is symmetric and for every . Then there is exactly one lower triangular with positive real diagonal entries such that
This is the Cholesky factorization of the earlier lesson, written with . A Cholesky solve of computes , solves by forward substitution and then solves by back substitution. The pivots are positive, so no row exchanges are needed, and the factorization takes about half the arithmetic of a general LU factorization. The hypotheses matter. If is Hermitian but not positive definite, no such factorization exists, and the computation reaches a step where the number under the square root is zero or negative. Cholesky fits a system whose matrix is given as positive definite. Applied to the normal equations of a least-squares problem, it solves a system with condition number and inherits the loss described above, however well the triangular steps themselves behave.
In plain words A positive definite matrix splits into a triangular factor times its conjugate transpose, and a solve becomes two triangular sweeps. Use it when positive definiteness is part of the given problem, not something you created by multiplying by .
Example For the normal-equations matrix above,
Forward substitution in gives and then , so . Back substitution in gives , so , and then , so , the same solution as before. The factor is exactly the triangular factor with positive diagonal in the QR factorization of the final card, because . Both routes reach the same triangle in exact arithmetic, but QR gets there without forming .
Partial pivoting
Definition Let be nonsingular, where is or . Gaussian elimination with partial pivoting works through the columns . At step it chooses, among the entries of column on or below the diagonal of the current matrix, one of largest absolute value, swaps its row into row , and subtracts multiples of row from the rows below. Because is nonsingular, a nonzero candidate always exists, and every multiplier satisfies . The result is
with a permutation matrix, unit lower triangular with entries of absolute value at most , and upper triangular and nonsingular. To solve , apply the same row swaps to , then solve and . Partial pivoting controls the multipliers at each step, but it does not keep the later entries small in general. Entries can grow by a factor up to relative to the largest entry of , and some matrices reach that factor. It also cannot repair an ill-conditioned matrix, because belongs to the problem, not to the method.
In plain words Divide by the entry of largest size available in the column, never by a tiny one when a large one sits below it. That keeps every multiplier at most in size. It is a safeguard for the algorithm, not a cure for a sensitive problem.
Example Let and solve
The exact solution is , and the matrix is well conditioned, with . Suppose every computed result is rounded to three significant digits. Without a swap the multiplier is . The new second row has , stored as , and right side , also stored as . So and then , which is completely wrong. With the swap the pivot is and the multiplier is . The new entries and are both stored as , so and , correct to three digits. The problem was harmless, and the damage came from the tiny pivot.
Rank-aware method choice
Definition Rank-aware method choice selects a solver from the stated task, its structure and what is known about its rank, rather than from the shortest formula. For real or complex data the standard choices are these.
- For a general nonsingular square system , use Gaussian elimination with partial pivoting.
- For a square system whose matrix is given as Hermitian positive definite, use a Cholesky solve.
- For least squares with of full column rank, use Householder QR. A reduced factorization , with having orthonormal columns and upper triangular and nonsingular, gives the solution of by back substitution, and in exact arithmetic the minimal residual satisfies . In floating point this difference loses digits when the residual is small, and computing the vector directly is more accurate. The method works with itself, whose condition number is , and never forms .
- When the rank is in doubt, use column-pivoted QR, which can help expose independent columns, or the SVD with , together with a tolerance set by the size of the data errors and the units. The numerical rank is the number of singular values , and directions with are dropped or regularized.
One way to drop them is the truncated SVD solution
Even a backward stable method only returns the exact solution of a nearby problem, so its forward error still depends on the conditioning of the problem itself. No factorization recovers information that the data never resolved.
In plain words Start from what the problem gives you. Given positive definiteness, use it. Given a tall matrix of full rank, keep it and use orthogonal factors. Given doubtful rank, compare the singular values with the noise before trusting any solution.
Example For the line fit above, one reduced QR factorization has
The columns of are orthonormal and . Then , and back substitution gives and , so again. The residual formula gives , which matches . This matrix is mild, with and , so both routes do well. For the nearly dependent columns of the Gram example, QR works with while the normal equations work with about .
Check yourself
- A matrix has full column rank and singular values , and . Find , the eigenvalues of and . What changes if the smallest singular value is instead?
Show the answer
The condition number is . The eigenvalues of are the squares , and , so .
If the smallest singular value is , then has rank , not full column rank. The matrix is singular, the least-squares solution is not unique, and in the sense of this lesson is not defined. The ratio of the positive singular values describes a different problem, the minimum-norm solution under the assumption that the rank is exactly , and it is not a substitute.
- Two symmetric matrices are given, with rows and , and with rows and . Decide which of them has a Cholesky factorization, and use it to solve that system with right-hand side .
Show the answer
The matrix has leading principal minors and , both positive, so it is positive definite. Its factor is built column by column, with , and , so
Forward substitution in gives and , so . Back substitution in gives , so , and , so . Check that .
The matrix has determinant and eigenvalues and , so it is symmetric but not positive definite. The algorithm shows the failure directly. It gives and , and then needs , which no real number satisfies. Symmetry alone is not enough, and a system with calls for another method, such as elimination with partial pivoting.
- Choose a method for each task and name the property of the data that justifies it. (a) Solve for the nonsymmetric matrix with rows , and , and carry out the first pivot step. (b) Solve for the exactly known matrix with rows , and . (c) Fit to five measurements taken at five different times. (d) Fit a model whose two measured columns are nearly parallel, with a noisy right-hand side.
Show the answer
(a) The matrix is not symmetric, so Cholesky does not apply, and , so this is a general nonsingular system for partial pivoting. Column has entries , and . The largest in absolute value is , so rows and are swapped, in and in . The multipliers are and , both at most , and the remaining rows become and . The next pivot is , with multiplier .
(b) The matrix is symmetric with leading principal minors , and , all positive, so it is positive definite and a Cholesky solve fits. Its pivots are , and , and the diagonal of holds their square roots.
(c) The design matrix has the columns and . They are independent because the times differ, so the matrix has full column rank and Householder QR fits. Forming the normal equations would square the condition number. For times the design matrix has , while its Gram matrix has .
(d) Full rank cannot be taken for granted here. Compute the SVD, or a column-pivoted QR, and compare the small singular value with a tolerance set by the noise level and the units. If it lies below the tolerance, the data do not determine the combination of coefficients along that singular direction, and it must be dropped, as in the truncated SVD solution, or regularized. If it lies well above the tolerance, full rank is trustworthy and QR is appropriate. No method can recover a combination that the measurements never resolved.