How to diagonalize a matrix

A matrix can be diagonalized whenever it is similar to some diagonal matrix.

The matrix A is said to be diagonalized by the matrix P when D = P–1AP is diagonal.

 

This theorem tells you when a matrix can be diagonalized and what the matrices P and D must be.

Let A be an n x n matrix. Then

a) If A has n linearly independent eigenvectors p1, p2, ..., pn with corresponding eigenvalues λ1, λ2, ..., λn, and if P is matrix with columns p1, p2, ..., pn, then P–1AP = D, where D is the diagonal matrix with entries λ1, λ2, ..., λn down the main diagonal.

b) If P–1AP = D for some matrix P and some diagonal matrix D with entries λ1, λ2, ..., λn down the main diagonal, then the columns of P are linearly independent and are eigenvectors of A with corresponding eigenvalues λ1, λ2, ..., λn.

Proof. First suppose D is a diagonal matrix with the numbers λ1, λ2, ..., λn along the main diagonal and P is any matrix with columns p1, p2, ..., pn.

We calculate AP and PD and compare them. Since the multiplication AP takes its rows from A and its columns from P, AP is the matrix with columns Ap1, Ap2, ..., Apn. On the other hand, PD is the matrix with columns λ1p1, λ2p2, ... , λnpn.

a) Now, first suppose that the vectors p1, p2, ..., pn are linearly independent eigenvectors of A with corresponding eigenvalues λ1, λ2, ..., λn. Then Api = λipi for i = 1, 2, ..., n, i.e. the matrices AP and PD have the same columns and so are equal: AP = PD. Since P is invertible (its columns are linearly independent), P–1AP = P–1PD = D.

b) On the other hand, suppose instead that P–1AP = D. This implies first that P is invertible (else P–1 wouldn't exist), so its columns p1, p2, ..., pn are linearly independent. Second, it implies that AP = PD, so AP and PD have the same columns, i.e. Api = λipi for i = 1, 2, ..., n. In other words, it implies that p1, p2, ..., pn are eigenvectors of A with corresponding eigenvalues λ1, λ2, ..., λn.

 

So your main concern when you try to diagonalize a matrix is whether or not you have enough linearly independent eigenvectors. It turns out that, if you find a basis of each eigenspace and then merge those bases, the resulting set of vectors will always be linearly independent; you need only worry about having enough of them.

To diagonalize a matrix

Given an arbitrary n x n matrix A:

Find all the eigenvalues of A and a basis for each eigenspace.

If you have fewer than n basis eigenvectors in total, you cannot diagonalize A.

If you have n basis eigenvectors in total, stack them into the columns of a matrix P.

The matrix D = P–1AP will be diagonal, and its diagonal entries will be the eigenvalues of A in the same order that you chose the corresponding eigenvector columns of P.