TITLE: How to generate $3 \times 3$ integer matrices with integer eigenvalues?
QUESTION [16 upvotes]: I am looking for an easy way to generate non-trivial (i.e., not just diagonal) examples of $3 \times 3$ matrices whose entries are integers and whose eigenvalues are also integers.
I know how to do this for $2 \times 2$ matrices: you just choose integers so that the discriminant of the characteristic equation is a perfect square. But short of trial and error, with the help of Wolfram Alpha, I don't know a way with larger matrices.
Does anyone know how to do this?

REPLY [2 votes]: Compute the product of two $2\times2$ unitary matrices:
$$
\begin{bmatrix}\color{#C00000}{3}&\color{#C00000}{7}&0\\\color{#C00000}{2}&\color{#C00000}{5}&0\\0&0&1\end{bmatrix}
\begin{bmatrix}1&0&0\\0&\color{#C00000}{2}&\color{#C00000}{3}\\0&\color{#C00000}{1}&\color{#C00000}{2}\end{bmatrix}
=\begin{bmatrix}3&14&21\\2&10&15\\0&1&2\end{bmatrix}
$$
and their inverses:
$$
\begin{bmatrix}1&0&0\\0&\color{#C00000}{2}&\color{#C00000}{-3}\\0&\color{#C00000}{-1}&\color{#C00000}{2}\end{bmatrix}
\begin{bmatrix}\color{#C00000}{5}&\color{#C00000}{-7}&0\\\color{#C00000}{-2}&\color{#C00000}{3}&0\\0&0&1\end{bmatrix}
=\begin{bmatrix}5&-7&0\\-4&6&-3\\2&-3&2\end{bmatrix}
$$
then compute a matrix similar to a diagonal using these:
$$
\begin{bmatrix}3&14&21\\2&10&15\\0&1&2\end{bmatrix}
\begin{bmatrix}1&0&0\\0&2&0\\0&0&3\end{bmatrix}
\begin{bmatrix}5&-7&0\\-4&6&-3\\2&-3&2\end{bmatrix}
=\begin{bmatrix}29&-42&42\\20&-29&30\\4&-6&6\end{bmatrix}
$$