Diagonalization
A diagonal matrix is the easiest matrix there is: it just scales each coordinate. Diagonalizing means finding a coordinate system, made of eigenvectors, in which becomes diagonal. When that works, powers, exponentials and long-run behaviour of all reduce to arithmetic on its eigenvalues.
The factorization
Suppose the matrix has linearly independent eigenvectors with eigenvalues . Put the eigenvectors in the columns of and the eigenvalues on the diagonal of :
Multiplying column by column, . The columns of are independent, so is invertible, and
A matrix is diagonalizable if it can be written this way. Read from right to left, says: convert a vector to eigenvector coordinates (), scale each coordinate by its eigenvalue (), convert back ().
A worked example
has eigenvalues 2 and 3 with eigenvectors and (see Finding Eigenvalues):
SymPy's diagonalize() returns and . It may order the eigenvalues differently from you, and scale the eigenvectors differently; any such choice is valid as long as column of belongs to the eigenvalue in position of .
from sympy import Matrix
A = Matrix([[4, -2], [1, 1]])
P, D = A.diagonalize()
print("P =", P.tolist())
print("D =", D.tolist())
print("P D P^-1 == A:", P * D * P.inv() == A)
print("P^-1 A P =", (P.inv() * A * P).tolist())P = [[1, 2], [1, 1]]
D = [[2, 0], [0, 3]]
P D P^-1 == A: True
P^-1 A P = [[2, 0], [0, 3]]
When is a matrix diagonalizable?
The whole question is whether there are enough independent eigenvectors:
| Situation | Diagonalizable? |
|---|---|
| distinct eigenvalues | always (eigenvectors of distinct eigenvalues are independent) |
| repeated eigenvalue, eigenspace as large as the multiplicity | yes |
| some eigenspace smaller than the eigenvalue's multiplicity | no |
| real symmetric matrix | always, even with an orthogonal (Diagonalization of Real Symmetric Matrices) |
In terms of Finding Eigenvalues: is diagonalizable exactly when, for every eigenvalue, (over the complex numbers, so that the characteristic polynomial splits into linear factors).
The standard counterexample is the shear : twice, but has a one-dimensional null space. There is only one eigenvector direction, so no invertible exists.
from sympy import Matrix
for name, M in [("[[4,1,1],[1,4,1],[1,1,4]]", Matrix([[4, 1, 1], [1, 4, 1], [1, 1, 4]])),
("shear [[1,1],[0,1]]", Matrix([[1, 1], [0, 1]])),
("[[2,1,0],[0,2,0],[0,0,3]]", Matrix([[2, 1, 0], [0, 2, 0], [0, 0, 3]]))]:
dims = {val: (mult, len(vecs)) for val, mult, vecs in M.eigenvects()}
print(f"{name:28} {{lambda: (alg, geo)}} = {dims} diagonalizable: {M.is_diagonalizable()}")[[4,1,1],[1,4,1],[1,1,4]] {lambda: (alg, geo)} = {3: (2, 2), 6: (1, 1)} diagonalizable: True
shear [[1,1],[0,1]] {lambda: (alg, geo)} = {1: (2, 1)} diagonalizable: False
[[2,1,0],[0,2,0],[0,0,3]] {lambda: (alg, geo)} = {2: (2, 1), 3: (1, 1)} diagonalizable: False
The first matrix has a repeated eigenvalue 3 but a two-dimensional eigenspace for it, so it is diagonalizable. The other two each have an eigenvalue whose eigenspace is too small. Matrices like these are handled by the Jordan form, which is beyond this course; in practice the matrices you meet in data and physics are very often symmetric, and those are always diagonalizable.
Change of basis
is the same linear transformation as , described in the basis of eigenvectors instead of the standard basis. Two matrices related by for some invertible are called similar. Similar matrices share their characteristic polynomial, eigenvalues, trace, determinant and rank (Properties of Eigenvectors and Eigenvalues). The general idea of "the matrix of a map in a chosen basis" is developed in The Matrix of a Linear Transformation.
In software
- Fast repeated application: costs two matrix products plus scalar powers (Application: Matrix Powers).
- Decoupling: a system of coupled equations becomes independent one-variable equations in eigenvector coordinates (Application: Systems of Linear Differential Equations).
- Spectral methods: graph clustering, PCA and the analysis of attention matrices all start from an eigen-decomposition.
Note: For numerical work prefer
np.linalg.eighon symmetric matrices. For a non-symmetric whose eigenvectors are almost parallel, is nearly singular and computing loses many digits even if is technically diagonalizable.
Exercises
Exercise 1: Diagonalize a triangular matrix
Diagonalize : give , and .
Answer
, , .
Solution
Exercise 2: Yes or no
Which of these are diagonalizable: (a) , (b) , (c) ?
Answer
(a) no, (b) yes, (c) yes.
Solution
(a) twice, has a 1-dimensional null space: not enough eigenvectors. (b) It is already diagonal (). (c) , , so has discriminant : two distinct real eigenvalues, so it is diagonalizable.
Exercise 3: Build a matrix from its eigen-data
Find the matrix with eigenvector for and eigenvector for . Check it in SymPy.
Answer
.
Solution
from sympy import Matrix, diag
P = Matrix([[1, 1], [2, -1]])
A = P * diag(3, 0) * P.inv()
print(A.tolist())
print(list(A * Matrix([1, 2])), list(A * Matrix([1, -1])))[[1, 1], [2, 2]]
[3, 6] [0, 0]
Exercise 4: Count the free parameters
A matrix has eigenvalues 5, 5, 2. The eigenspace of 5 is a plane. Is diagonalizable? What if the eigenspace of 5 were a line?
Answer
Plane: yes. Line: no.
Solution
always contributes one eigenvector. A plane of eigenvectors for 5 adds two independent ones, three in total, so is invertible. With only a line for , there are two independent eigenvectors in total, one short of three.
Test yourself
In , what are the columns of ?
- The rows of
- Eigenvectors of
- The eigenvalues of
- The columns of
Which condition guarantees that an matrix is diagonalizable?
- It has distinct eigenvalues
- It is invertible
- Its determinant is 1
- It has a repeated eigenvalue
Similar matrices and always share…
- their eigenvectors
- their entries
- their eigenvalues
- their columns