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.
No, there is no problem with your program, we can easily prove that any $2\times 2$ matrix with coefficients in $[\![ 1, 9]\!]$ is diagonalizable.
Let $\displaystyle M = \begin{bmatrix} a & b\\ c & d \end{bmatrix}$ with $(a,b,c,d) \in [\![ 1, 9]\!]^4$.
We can calculate the characteristic polynomial of $\displaystyle M.$
\begin{equation*} \begin{split} \chi_{M} & = \det(XI_{2} - M) \\ & = \begin{vmatrix} X-a & -b \\ -c & X-d \end{vmatrix} \\ & = (X-a)\cdot(X-d)-cb \\ & = X^2 + (-a-d)\cdot X + ad - cb \end{split} \end{equation*}
Let $\displaystyle x$ be a complex number, let's solve $\displaystyle \chi_{M}(x) = 0 $ for $\displaystyle x$:
$\displaystyle x^2 + (-a-d)\cdot x + ad - cb = 0 $ gives us
\begin{equation*} \begin{split} \Delta & = a^2 + 2 \cdot ad + d^2 - 4 \cdot (ad - cb) \\ & = a^2 + d^2 - 2 \cdot ad + 4\cdot cb \end{split} \end{equation*} Since $\displaystyle a^2 + d^2 - 2 \cdot ad = (a-d)^2 \ge 0$ and $\displaystyle 4\cdot cb > 0$ because $\displaystyle (c,b) \in [\![ 1, 9]\!]^2$.
We can ensure that $\displaystyle \Delta > 0$ and therefore, $\displaystyle \chi_{M}$ has two distinct real roots:
$\displaystyle x_1 = \frac{a+d - \sqrt{ \Delta }}{2} \quad$ and $\displaystyle \quad x_2 = \frac{a+d + \sqrt{ \Delta }}{2}$
Therefore, $\text{Sp} \displaystyle (M) = \{x_1, x_2\} $ with $\displaystyle x_1 \ne x_2 $, which ensures that M is diagonalizable.
So yes, every $2\times 2$ matrices with coefficient between 1 and 9 is diagonalizable.