Gram-Schmidt process Created 2026-09-24 Updated 2026-10-14
The Gram-Schmidt process turns a finite ordered family of linearly independent vectors in an inner product space over the real numbers into an orthonormal basis of their linear span. It keeps every successive linear span, so the first new vectors describe exactly the same directions as the first inputs. Its idea is geometric: remove the orthogonal projection onto directions already found, then divide the remaining vector by its norm. This makes a complicated basis easier to use without changing the vector subspace it describes.[ref]
Start with and . At step , use the previously obtained orthonormal set to define
The sum is the orthogonal projection onto a finite-dimensional subspace , and is the orthogonal projection residual. Linear independence ensures : otherwise would already be a linear combination of earlier inputs. If the input family is linearly dependent, use only the retained orthonormal vectors in the sum and omit an input whenever its remainder is the zero vector; do not divide by zero. The retained outputs still form an orthonormal basis of the original linear span, but their number can be smaller than .
For a short verification, orthonormality makes every earlier inner product vanish:
Also is minus a linear combination of earlier vectors, while is plus that same linear combination. These two inclusions, followed by division by a nonzero norm, give
The argument also works in an inner product space over the complex numbers with the existing inner product convention, linear in the first argument: the coefficients remain . With the convention linear in the second argument, write instead.
For a first picture, take and in with the ordinary dot product. Then
Subtracting the diagonal component leaves an orthogonal direction; dividing by its norm makes its length one. If the second input were instead, its orthogonal projection would be the entire input and , revealing linear dependence.
For a full three-dimensional calculation, use the ordinary dot product and the input vectors
The first two steps give
At the third step, the inner products are and . Consequently
The three numerator vectors have pairwise dot products and squared Euclidean norms . Thus the displayed outputs are indeed an orthonormal basis, and the three nonzero remainders also confirm linear independence of the inputs. Keeping the removed coefficients produces the QR decomposition below.
An immediate reward is a reusable orthogonal projection: once an orthonormal basis of a vector subspace is known, any vector has
For the linear span of just the first two inputs in the three-dimensional example, gives . Its orthogonal projection residual is , visibly in the missing orthogonal direction. This is the geometry behind the linear least-squares problem.
The formulas above describe exact arithmetic. With floating-point arithmetic, subtracting an orthogonal projection nearly equal to the input can leave a small remainder; dividing by its small norm can magnify existing roundoff error. The Classical Gram-Schmidt and Modified Gram-Schmidt arrangements agree in exact arithmetic but can give different rounded results. Exact linear dependence and a small computed remainder therefore require different judgments in a numerical implementation.[ref]
Let and consider an arbitrary variation . The objective for the linear least-squares problem is
At a minimizer the derivative at must vanish for every , so . Conversely, when this holds, the same expansion at gives for every . Thus minimizes the residual norm if and only if . These least-squares normal equations do not require to have full rank; without full rank the minimizing vector need not be unique.
The original PDF has , not the 2 in the converted TeX. Using the PDF's matrix gives
The least-squares normal equations consequently have the unique solution
As a direct check, , whose inner product with either column of is zero. The positive determinant verifies full column rank for this particular problem.
A full QR decomposition of a real by matrix with writes
where is an orthogonal by matrix and is upper triangular by . In the full-column-rank case is invertible. Equivalently the reduced factorization is with . Householder transformations can construct the full factorization.
Let with . Since orthogonal transformations preserve the Euclidean norm,
Therefore the linear least-squares problem has the full-rank solution
Back substitution solves this triangular system without forming . If the matrix is rank deficient, use a rank-revealing pivoted factorization and minimize over its independent columns; the minimizer need not be unique. The original PDF minimizes over ; the converted TeX's minimization over is a transcription error.
The linear least-squares problem is to minimize over , allowing an overdetermined system to have a nonzero residual. For a full QR decomposition, is orthogonal and is with an upper-triangular top block. Orthogonal transformations preserve the Euclidean norm, so
If has full column rank, the top triangular block is nonsingular; setting its residual to zero gives the unique minimizer, while the remaining residual is independent of . Without full column rank, minimizers still exist but need not be unique.
For the specified matrix, one Householder reflection already produces an upper-triangular matrix. Take , the difference between the first column and , and set
The formula gives , . Direct multiplication yields the Householder QR decomposition
All subdiagonal entries in the remaining columns are already zero, so no further reflection is needed. For the supplied right-hand side, . Back substitution gives , , , hence
The residual is orthogonal to every column of , independently confirming the normal equations .
The linear least-squares problem is to choose minimizing the Euclidean norm of the residual:
For a QR decomposition , orthogonality of gives . If has full column rank and is in standard form with invertible upper-triangular , the minimizer solves .
Applying the Gram-Schmidt process to the columns of the given matrix yields
Indeed, is an orthogonal matrix and . Moreover,
Back substitution in the leading triangular system gives
so the unique least-squares solution is
The unused final transformed residual component is , so the minimum residual norm is .
For , define by . If , then in particular
so . Thus is injective. Since a finite-dimensional vector space and its dual space have the same dimension, is also surjective and hence an isomorphism. This is the finite-dimensional real case of the Riesz representation theorem.
The adjoint operator of is the unique linear map satisfying
for every and . In the stated orthonormal bases, if and denote coordinate columns, then
Therefore the matrix of is the matrix transpose .
For ,
Hence . Taking orthogonal complements in the finite-dimensional space proves the image-kernel orthogonality for an adjoint
Put . For any ,
This is minimized at exactly when , equivalently when . Thus the normal equation for a linear inverse problem is
For the given linear least-squares problem,
The normal equations and have the unique solution
QR decomposition Created 2026-09-24 Updated 2026-10-14
A reduced QR decomposition of an matrix over the real numbers with full column rank, , writes , where is with orthonormal columns and is a upper triangular matrix with positive diagonal. Applying the Gram-Schmidt process to the columns of constructs and records the coefficients
This last column identity is exactly the matrix multiplication . The upper triangular matrix records that the th input uses only the first new directions, while its positive diagonal records the norms of the nonzero orthogonal projection residuals. Since , one also has ; denotes the transpose and the identity matrix. Over the complex numbers, use the conjugate transpose in these identities.
For the three-dimensional Gram-Schmidt process example, the exact matrices are
For example, the last column reconstructs as
The diagonal entries are approximately . Each is a norm of the new direction before it was scaled to length one.
For a linear least-squares problem, the orthogonal projection of onto the column space of is . Hence the minimizing coefficients solve the linear system by back substitution. Let consist of the first two columns of the example; its reduced factors are and the leading block of . For , the linear system is
Thus , agreeing with the orthogonal projection computed above, and the minimum Euclidean norm of is . The QR decomposition separates building an orthonormal basis from recovering coefficients in the original basis.[ref]
QR decomposition by Givens rotations Created 2026-09-24 Updated 2026-10-14
Successive Givens rotations eliminate entries below the diagonal of a matrix. For an matrix with , process columns ; within column , rotate rows for each whose entry needs elimination. Apply each Givens row-pair update to columns . Both rows are zero in earlier columns, so these operations preserve earlier eliminations. No assumption of full column rank is needed to perform the eliminations.
For a concrete example, take
First use , then :
The entry in position was already zero, so its elimination was skipped. The second Givens rotation combines the remaining pair in column two. This yields the full QR decomposition
The first two columns of and first two rows of give the reduced QR decomposition. Direct multiplication verifies both and . For these displayed factors evaluated in binary64 floating-point arithmetic, the Frobenius norms and are both below ; these measure reconstruction and loss of orthogonality separately.
Figure 1.
Two local Givens row-pair updates turn a matrix into the rectangular of a QR decomposition
. Details.
More generally, if the chronological rotations are , then
Each factor is an orthogonal matrix, so is too. For a rectangular matrix, has zeros below its diagonal; its leading block is an upper triangular matrix. With full column rank, retaining the first columns of gives orthonormal columns. To impose a positive diagonal when necessary, flip matching columns of and rows of , preserving their product.
For a linear least-squares problem, apply the same chronological Givens rotations to the right-hand side , obtaining , without explicitly constructing . Since the Euclidean norm is preserved, solve the leading upper triangular matrix system by back substitution when has full column rank; the remaining entries of give the minimum residual norm. In the example, gives , , and minimum residual Euclidean norm .
The locality is useful for a sparse matrix or an existing QR decomposition needing an extra row: only two rows change at each step, and the new row can be eliminated against the stored upper triangular matrix. For an factor, this extra-row procedure takes rotations and arithmetic operations. Locality does not guarantee preservation of sparsity: mixing rows can create nonzeros wherever either row had one. For a fully populated input, the straightforward elimination uses rotations, each touching columns, giving work. Storage layout, zero patterns and implementation affect speed; this count alone establishes no universal advantage over other QR decomposition algorithms.
The Euclidean norm preservation explains the appeal for numerical stability: exact rotations do not amplify a perturbation's length. Rounded coefficients and Givens row-pair updates still introduce roundoff error. Small reconstruction and orthogonality residuals check the computed factors, while the condition number of the original problem still controls how accurately a linear least-squares problem determines its solution.