How to generate $3 \times 3$ integer matrices with integer eigenvalues?

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?


How about the following:

  1. Pick a diagonal matrix $\Lambda$ with integer diagonal entries. The eigenvalues will be multiples of these.
  2. Pick a matrix $V$ with integer entries so that $V$ is invertible, $\det(V)\neq 0$.
  3. Form $A=\det(V)V\Lambda V^{-1}$.

$A$ is guaranteed to have integer entries. One formula for the inverse of $V$ is $V^{-1}=\frac{1}{\det(V)}\mathrm{adj}(V)$ where $\mathrm{adj}(V)$ is the adjugate of $V$. The adjugate has integer entries since the entries are determinants of minors of $V$.

The eigenvalues of $A$ are the diagonal entries of $\Lambda$ scaled by $\det(V)$. Note that you can always pick $V$ to have a unit determinant. For example, choose $V$ as upper Hessenberg with 1's on the first subdiagonal. Then the upper right corner entry can be used to control the determinant and ensure it is $\pm 1$ (or any other desired value).

As an example, take $\Lambda=\left[\begin{array}{ccc}17&0&0\\0&-2&0\\0&0&3\end{array}\right]$ and $V=\left[\begin{array}{ccc}2&3&x\\1&-1&5\\0&1&1\end{array}\right]$. Then $\det(V)=-15+x$ so we can choose $x=16$ to get $\det(V)=1$. The result is $A=\left[\begin{array}{ccc}-150&334&778\\-89&195&464\\5&-10&-27\end{array}\right]$.


Here's an example. Say you want the eigenvector to be $v=(1,2,3)$ and the eigenvalue to be $\lambda=5$. First, calculate the norm squared of the eigenvector. In this example, $\|v\|^2=14$. Now multiply the eigenvalue divided by the norm squared times the column {1,2,3} times the row {1,2,3}. The result is $$\frac{5}{14}\left( \matrix{1 & 2 & 3 \\ 2& 4& 6\\3& 6& 9} \right)$$

Of course, this matrix doesn't have integer entries, because of the 14 in the denominator. For this choice of eigenvector, we would have to choose an eigenvalue that is a multiple of 14 to get a matrix with all integer entries.

As another example, say we have two orthogonal vectors $u=(1,1,1)$ and $v=(-1,0,1)$. The first norm squared is 3 and the second norm squared is 2. So let's choose eigenvalue 6 for the first vector and eigenvalue -2 for the second. For each eigenvalue/eigenvector pair, we form the matrix like we did above, and then add the two matrices. $$ \frac{6}{3}\left( \matrix{ 1& 1& 1\\ 1& 1& 1\\ 1& 1& 1}\right)+ \frac{-2}{2}\left( \matrix{ 1& 0& -1\\ 0& 0& 0\\ -1& 0& 1}\right)= \left( \matrix{ 1& 2& 3\\ 2& 2& 2\\ 3& 2& 1}\right)$$ If you have a third orthogonal vector, then you could form a third matrix and add that one. For example, $w=(1,-2,1)$ is orthogonal to $u$ and to $v$, and it has a norm squared of 6, so we could use it to form a matrix with integer entries and an integer eigenvalue that is any multiple of 6.

For me the only tricky part is in multiplying column vector on left by the row vector on the right to get a matrix. Here's the formula for that:$$ \left( \matrix{x\\ y\\ z}\right) \left( \matrix{a& b& c}\right) = \left( \matrix{ ax& bx& cx\\ ay& by& cy\\ az& bz& cz}\right) $$

You can use this method for larger (4x4, etc) or smaller (2x2) matrices.


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} $$