LU, QR, and Polar Decompositions
We discuss some consequences of the spectral theorem and of our study of unitary and orthogonal matrices that are important in applications.
The LU decomposition
This decomposition actually has nothing to do with the spectral theorem; it’s just a restatement of Gaussian elimination, but it will be useful to have for reference at this point.
Proposition: Let A be an n\times m matrix (over any field). Then there exist an n\times n permutation matrix P, an n\times n matrix L, and an n\times m matrix U, where L is lower triangular and U is upper triangular (u_{ij}=0 when i>j), such that PA=LU.
The proof is just Gaussian elimination. Start with A and apply row operations to it so that it becomes upper triangular. Generically, each diagonal entry in turn can serve as a pivot, and the row operations correspond to left multiplication of A by a sequence E_1,\ldots,E_k of elementary matrices that are lower triangular with ones on the diagonal. So E_{k}E_{k-1}\cdots E_{1}A = U and then L=(E_{k}E_{k-1}\cdots E_{1})^{-1}.
In the general case one may need to permute the rows of A so that a nonzero pivot is available at each step. Then one collects those permutations into a permutation matrix P and replaces A by PA. If A is singular (or not square), U may have zeros on its diagonal. We won’t treat any of these special cases in detail here.
The QR decomposition
Let X be an n\times k matrix with real or complex entries. The QR decomposition says that (assuming the columns of X are linearly independent) we can find an n\times n orthogonal (or unitary) matrix Q and an n\times k upper triangular matrix R such that X = QR.
This is just a version of the Gram–Schmidt algorithm. Gram–Schmidt applied to the columns x_1,\ldots, x_k of X yields an orthonormal sequence of vectors u_1,\ldots, u_k where (setting U to the matrix with columns equal to the u_{i}): U = XS
where S is k\times k and upper triangular. (See the Gram–Schmidt process). Then X=US^{-1}. Extend U by adding orthonormal columns to make it an orthogonal/unitary n\times n matrix Q and add zero rows to S^{-1} so that it becomes an upper triangular n\times k matrix; this extended matrix is the matrix R. This gives us X=QR as claimed.
Application to Least Squares
Recall our discussion of the least squares problem. We are given an N\times k matrix X. Each row represents a set of measurements, or features, of a piece of sample data, and the N rows together represent a full set of measurements. We also have, for each sample, a dependent, target variable whose values form an N\times 1 vector Y. We believe there are “weights” m_{j} such that y_{i} = \sum_{j=1}^{k} m_{j}x_{ij}+b + \epsilon_i where \epsilon_i is a random error.
We let M be the (k+1)\times 1 vector whose entries are the m_{j} and set m_{k+1}=b. We also let X' be the matrix obtained from X by adding a column of 1’s. Then (thinking of \epsilon as a random vector) the equation above becomes Y = X'M + \epsilon
We showed that the “best” choice for the m_{j} and b, in the sense that it minimizes the squared error S(M) = \|Y-X'M\|^2
is given by solving the “normal equations” (X')^{\top}Y = (X')^{\top}X'M
Use Gram–Schmidt, as in the QR decomposition, to write X'=US^{-1}=UK where U has orthonormal columns and K is a (k+1)\times (k+1) upper triangular matrix. Then: (X')^{\top} = K^{\top}U^{\top} and (X')^{\top}X' = K^{\top}U^{\top}UK
Since U has orthonormal columns, U^{\top}U is the (k+1)\times (k+1) identity matrix. Also (assuming the columns of X' were linearly independent) the matrix K is invertible so the “normal equations” become
U^{\top}Y = KM
Since K is upper triangular, you can solve this system by “back substitution”.
The QR decomposition and finding eigenvalues
The QR decomposition is the basis for a standard numerical algorithm for the computation of the eigenvalues and eigenvectors of a matrix. While it can be applied to general matrices (with some caveats) we will consider positive real symmetric matrices for simplicity.
Motivation
Suppose A is a positive real n\times n symmetric matrix with eigenvalues \lambda_{1}>\lambda_{2}>\cdots>\lambda_{n}. We know that there exists an orthonormal basis u_1,\ldots, u_{n} of corresponding eigenvectors for A.
Choose a vector v=v_{0} at random and consider the following iteration:
- Set v_{k+1}=Av_{k}/\|Av_{k}\|
Then the sequence v_{k} converges to the eigenvector u_{1} corresponding to the largest eigenvalue \lambda_{1}.
To see why this works, write v_{0} = \sum_{i=1}^{n} a_{i} u_{i} where \sum |a_{i}|^2 =1 and \langle v_{0},u_{1}\rangle = a_{1}. We assume a_{1}\not=0, which holds with probability one for a randomly chosen v_{0}.
Now v_{k} is a unit vector that points in the direction of A^{k}v_{0}. But \begin{aligned} A^{k}v_{0} &= \sum_{i=1}^{n} a_{i}\lambda_{i}^{k}u_{i} \\ &= \lambda_{1}^{k} \sum_{i=1}^{n} a_{i}(\lambda_{i}^{k}/\lambda_{1}^{k}) u_{i} \end{aligned} Since \lambda_{1}>\lambda_{i} for i>1, we see that A^{k}v_{0} = \lambda_{1}^{k}(a_{1}u_{1}+e) where e\to 0 at least as fast as (\lambda_{2}/\lambda_{1})^k. The normalized vector v_{k} therefore gradually aligns with u_{1} as k\to\infty.
### The full algorithm
Conceptually, the full QR algorithm uses the same idea we just discussed, but at each stage we don’t just normalize Av_{k}, but we successively apply Gram–Schmidt to A^{k}, so each column converges to the corresponding element u_{i} of an orthonormal basis.
Algorithm: Let A=A_0 be an n\times n real symmetric matrix. Define a sequence of matrices:
- Let A_{k} = Q_{k} R_{k} be the QR decomposition of A_{k}.
- Let A_{k+1}=R_{k}Q_{k}.
Notice that A_{k+1}=Q_{k}^{-1}A_{k}Q_{k} so all matrices A_{j} are orthogonally equivalent and have the same eigenvalues.
In addition if we put \overline{Q}_{k}=Q_{0}Q_{1}\cdots Q_{k-1} and \overline{R}_{k} =R_{k-1}R_{k-2}\cdots R_{0} then A_{k} = \overline{Q}_{k}^{\top}A\overline{Q}_{k} and A^{k} = \overline{Q}_{k}\overline{R}_{k}.
We can compute \overline{Q}_{k} directly by applying Gram–Schmidt to the columns of A^{k}.
The sequence A_{j} converges to a diagonal matrix whose entries are the eigenvalues of A. The sequence \overline{Q}_{k} converges to a matrix whose columns are the eigenvectors of A.
Let A= \begin{pmatrix} 2.1948 & 0.5638 \\ 0.5638 & 2.6052 \\ \end{pmatrix}
The algorithm above generates a sequence of (symmetric) matrices A_{k}, all similar to A which converge to a diagonal matrix, thereby revealing the eigenvalues of A.
The animation below plots the level curves u^{\top}A_{k}u=1 where u=\begin{pmatrix} x \\ y \end{pmatrix}. These are ellipses, each obtained from the previous one by a rotation by an orthogonal matrix. Ultimately the major and minor axes lie along the x and y axes, which is what happens when A_{k} approaches its limiting diagonal form.
The second graph shows the decay in the off-diagonal entry in the matrix A_{k}. It decays linearly with \log(\lambda_{2}/\lambda_{1}) where \lambda_{1}>\lambda_{2} are the eigenvalues of A.