How many non-diagonalizable $2\times 2$ matrices are there with all entries single-digit strictly positive integers?

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.


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.

In terms of the entries of $A$, $$\Delta = [-(a + d)]^2 - 4 (a d - b c) = (a - d)^2 + 4 b c,$$ but $(a - d)^2$ is nonnegative and $4 b c > 0$.