QR Decomposition with the Gram-Schmidt Algorithm

QR decomposition is another technique for decomposing a matrix into a form that is easier to work with in further applications. The QR decomposition technique decomposes a square or rectangular matrix, which we will denote as , into two components, , and .

Where is an orthogonal matrix, and is an upper triangular matrix. Recall an orthogonal matrix is a square matrix with orthonormal row and column vectors such that , where is the identity matrix. The term orthonormal implies the vectors are of unit length and are perpendicular (orthogonal) to each other.

QR decomposition is often used in linear least squares estimation and is, in fact, the method used by R in its lm() function. Signal processing and MIMO systems also employ QR decomposition. There are several methods for performing QR decomposition, including the Gram-Schmidt process, Householder reflections, and Givens rotations. This post is concerned with the Gram-Schmidt process.

The Gram-Schmidt Process

The Gram-Schmidt process is used to find an orthogonal basis from a non-orthogonal basis. An orthogonal basis has many properties that are desirable for further computations and expansions. As noted previously, an orthogonal matrix has row and column vectors of unit length:

Where is a linearly independent column vector of a matrix. The vectors are also perpendicular in an orthogonal basis. The Gram-Schmidt process works by finding an orthogonal projection for each column vector and then subtracting its projections onto the previous projections . The resulting vector is then divided by the length of that vector to produce a unit vector.

Consider a matrix with column vectors such that:

The Gram-Schmidt process proceeds by finding the orthogonal projection of the first column vector .

Because is the first column vector, there is no preceeding projections to subtract. The second column is subtracted by the previous projection on the column vector:

This process continues up to the column vectors, where each incremental step is computed as:

The is the norm which is defined as:

The projection can also be defined by:

Thus the matrix can be factorized into the matrix as the following:

Gram-Schmidt Process Example

Consider the matrix :

We would like to orthogonalize this matrix using the Gram-Schmidt process. The resulting orthogonalized vector is also equivalent to in the decomposition.

The Gram-Schmidt process on the matrix proceeds as follows:

Thus, the orthogonalized matrix resulting from the Gram-Schmidt process is:

The component of the QR decomposition can also be found from the calculations made in the Gram-Schmidt process as defined above.

The Gram-Schmidt Algorithm in R

We use the same matrix to verify our results above.

A

The following function is an implementation of the Gram-Schmidt algorithm using the modified version of the algorithm. A good comparison of the classical and modified versions of the algorithm can be found here. The Modified Gram-Schmidt algorithm was used above due to its improved numerical stability, which results in more orthogonal columns over the Classical algorithm.

gramschmidt 1) {
for (i in 1:(j-1)) {
r[i,j]

Perform the Gram-Schmidt orthogonalization process on the matrix using our function.