Sunday, July 8, 2012

How to diagonalize a matrix

Consider a matrix
$A=\begin{bmatrix} 1 & 2 & 0 \\ 0 & 3 & 0 \\ 2 & -4 & 2 \end{bmatrix}.$
This matrix has eigenvalues
$\lambda_1 = 3, \quad \lambda_2 = 2, \quad \lambda_3= 1.$
So A is a 3-by-3 matrix with 3 different eigenvalues, therefore it is diagonalizable. Note that if there are exactly n distinct eigenvalues in an n×n matrix then this matrix is diagonalizable.
These eigenvalues are the values that will appear in the diagonalized form of matrix $A$, so by finding the eigenvalues of $A$ we have diagonalized it. We could stop here, but it is a good check to use the eigenvectors to diagonalize $A$.

The eigenvectors of A are
$v_1 = \begin{bmatrix} -1 \\ -1 \\ 2 \end{bmatrix}, \quad v_2 = \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}, \quad v_3 = \begin{bmatrix} -1 \\ 0 \\ 2 \end{bmatrix}.$
One can easily check that $A v_k = \lambda_k v_k.$
Now, let P be the matrix with these eigenvectors as its columns:
$P= \begin{bmatrix} -1 & 0 & -1 \\ -1 & 0 & 0 \\ 2 & 1 & 2 \end{bmatrix}.$
Note there is no preferred order of the eigenvectors in P; changing the order of the eigenvectors in P just changes the order of the eigenvalues in the diagonalized form of A.
Then P diagonalizes A, as a simple computation confirms:
$P^{-1}AP = \begin{bmatrix} 0 & -1 & 0 \\ 2 & 0 & 1 \\ -1 & 1 & 0 \end{bmatrix} \begin{bmatrix} 1 & 2 & 0 \\ 0 & 3 & 0 \\ 2 & -4 & 2 \end{bmatrix} \begin{bmatrix} -1 & 0 & -1 \\ -1 & 0 & 0 \\ 2 & 1 & 2 \end{bmatrix} = \begin{bmatrix} 3 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 1\end{bmatrix}.$
Note that the eigenvalues $\lambda_k$ appear in the diagonal matrix.

Alternative Method

Starting with: $PD = AP$, where $P = [\vec{p_1}, \vec{p_2}]$, and the Diagonalization matrix $D$ is:
$D=\begin{bmatrix} d_{11} & 0 \\ 0 & d_{22} \end{bmatrix}$
Distribute $A$ into the column vectors of $P$.
$PD = [A\vec{p_1},A\vec{p_2}]$
Then $D$ can be broken down to its column vectors as follows:
$P[d_{11}\vec{e_1},d_{22}\vec{e_2}] = [A\vec{p_1},A\vec{p_2}]$
Multiplying $P$ on the left side of the equation gives:
$[\vec{d_{11}}\vec{p_1}, \vec{d_{22}}\vec{p_2}] = [A\vec{p_1},A\vec{p_2}]$
Setting each entry of the matrix to its corresponding entry:
$\vec{d_{11}}\vec{p_1} = A\vec{p_1}$
$\vec{d_{22}}\vec{p_2} = A\vec{p_2}$
Then the equations can be solved as follows, using the same process for both:
$(d_{11}I)\vec{p_1} = A\vec{p_1}$
$(d_{11}I-A)\vec{p_1} = 0$
and it solves for $d_{11}$, which is the first entry in the diagonal matrix, and also the first eigenvalue.