[Math] how many $3\times 3$ matrices with entries from $\{0,1,2\}$.

combinatorics

How many $3 × 3$ matrices $M$ with entries from $\left\{0, 1, 2\right\}$ are there for which taken from

the sum of the main diagonal of $M^TM$ is $5$.

Attempt: Let $M = \begin{pmatrix}
a & b & c\\
d & e & f\\
g & h & i
\end{pmatrix}$. where $a,b,c,d,e,f,g,h,i\in \{0,1,2\}$

$$M^{T}M= \begin{pmatrix}
a & d & g\\
b & e & h\\
c & f & i
\end{pmatrix}\begin{pmatrix}
a & b & c\\
d & e & f\\
g & h & i
\end{pmatrix} $$.

sum of diagonal entries $$a^2+b^2+c^2+d^2+e^2+f^2+g^2+h^2+i^2 = 5$$

How can I form different cases?

Best Answer

Positioning the $0$'s, we get $\dbinom94=126$ for the $'000011111'$ case.

For the $'000000012'$ case, we have $\dbinom97=36$ ways to position the $0$'s, we need to multiply this by $2!$ to account for the two cases $12, 21$.

Total: $126+72=198$.