I'd like to know how many non-diagonalizable size 2 matrices there are with integer coefficient between 1 and 9.
I built a python program which counts the non-diagonalizable matrices with such coefficients:
from sympy import *
count = 0
for a in range(1,10):
for b in range(1,10):
for c in range(1,10):
for d in range(1,10):
M = Matrix([[a,b],[c,d]])
if not M.is_diagonalizable():
pprint(M)
count+=1
print("Number of non-diagonalizable matrices :", count)
The output was :
Number of non-diagonalizable matrices : 0
I wonder if there is a problem with my program or if it's true, that all the size 2 matrices with integer coefficient between 1 and 9 are diagonalizable.
Please help me.
Best Answer
In fact every $2 \times 2$ matrix with positive real entries has distinct eigenvalues and so is diagonalizable.
Hint The eigenvalues of $$A = \pmatrix{a&b\\c&d}$$ are the roots of the characteristic polynomial $p_A(t) = t^2 - (\operatorname{tr} A) t + \det A$, and these roots coincide iff the discriminant $\Delta = (-\operatorname{tr} A)^2 - 4 \det A = 0$ vanishes.