QR factorizations
Recall that each elementary row operation in Gaussian Elimination could be interpreted as multiplication by a particular matrix. When thinking this way, you realize you are actually factoring a matrix when running Gaussian Elimination. This realization results in the LU factorizations with pivoting.
Similarly, we can view Gram Schmidt as a factorization, called a QR factorization.
First we notice that we can unfold the recursive definition given for Gram-Schmidt to write:
We can combine the as columns of a single matrix and we let be the matrix with
The matrix from its definition is upper triangular. For this reason, the QR decomposition is sometimes called the QU decomposition.
The matrix is an orthogonal matrix. Recall from this means the transpose of is its inverse:
Lemma. A matrix is orthogonal if and only if its columns form an orthonormal basis.
Proof. (Expand to view)
Let’s look at . The i,j entry of is If we want this to be the identity matrix, it is equivalent to requiring that
But this is exactly expressing that the vectors are an orthonormal set in . Any orthonormal set is linearly independent and we have as many as the dimension of . Thus we have a basis. ■
Knowing this, we have the following.
Theorem(QR Decomposition). For an invertible matrix with entries in , there exists an orthogonal matrix and an upper triangular matrix with
Proof. (Expand to view)
We take to have columns given by applying Gram-Schmidt to the columns of and taking to be the matrix of pairings between columns of and those of as above. ■
There is another useful characterization of orthogonal matrices. Given an inner product on a vector space , we say that an matrix preserves the inner product if In other words, applying to the two inputs and then taking the product returns the same number as just applying the product to the two inputs directly.
Lemma. An matrix preserves an the standard inner product on if and only if is orthogonal.
Proof. (Expand to view)
We have If is orthogonal, then this is equal to .
If we assume for all , then taking and we have Since we must have ■
As mentioned earlier, in Sage there is a method A.gram_schmidt()
for a matrix . It returns a decomposition very close to the QR one.
- First it consumes a matrix whose rows are the vectors in the basis.
- It returns where has orthogonal rows and is lower triangle. The rows here are the ’s from the Gram-Schmidt as the rows of . While has ’s along the diagonal and for the entries below the diagonal.
There is a function on lists of vectors in Sage that will perform Gram-Schmidt alone.
sage: B = [vector([1,2,1/5]), vector([1,2,3]), vector([-1,0,0])]
sage: from sage.modules.misc import gram_schmidt
sage: G, mu = gram_schmidt(B)
sage: G
[(1, 2, 1/5), (-1/9, -2/9, 25/9), (-4/5, 2/5, 0)]
The example is taken from its documentation.