How to construct a $4 \times 4$ symmetric, positive definite matrix with integer eigenvalues As part of my master thesis I'm trying to construct (or find) some $4 \times 4$ symmetric, positive (semi-)definite matrices with integer components, and integer eigenvalues. The reason for the integer conditions is purely aesthetical, since typesetting the matrix and many analytical calculations look nicer with integer scalars.
I'm aware of answers such as https://math.stackexchange.com/a/1377275/245055, but the problem is that this does not produce a symmetric matrix.
Any guidance will be greatly appreciated, as I would very much prefer not having to search for this by brute force or via code (which might potentially produce false positives due to numerical precision issues).
 A: You can use the trick from this paper to find orthogonal matrices with rational entries: $(S-I)^{-1}(S+I)$, where $S$ is skew-symmetric with integer entries. Then you can use these for similarity transforms of diagonal matrices $D$ with integer entries, and multiply by the determinants to get back to integers; all together:
$$
\det(S+I)^2(S+I)^{-1}(S-I)D(S-I)^{-1}(S+I)
$$
where $S$ is skew-symmetric, $D$ is diagonal and both have integer entries.
A: One can modify the approach of the linked solution. Borrowing the notation from there, we want the resulting matrix $A = (\det V) V \Lambda V^{-1}$ to satisfy $A^T = A$, and it is sufficient to choose $V$ such that $V^{-1} = V^T$, that is, such that $V$ is orthogonal. This actually gives only $n!$ solutions over $\Bbb Z$, namely the permutation matrices, and these only yield diagonal matrices, but we can just allow ourselves to work with rational orthogonal matrices $V$ and then clear denominators at the end. For $n \geq 2$ there are infinitely many of these, as any Pythagorean triple $(a, b, c)$ determines such a matrix:
$$\begin{pmatrix}\frac{a}{c} & -\frac{b}{c} \\ \frac{b}{c} & \frac{a}{c}\end{pmatrix} \oplus I_{n - 2} .$$ Alternatively, one could take a Householder reflection determined by any rational vector in $\Bbb Q^3$.
Explicitly:


*

*Pick any sequence $(d_1, \ldots, d_4)$ of nonnegative integers and form the diagonal matrix $$D := \pmatrix{d_1 & & \\ & \ddots & \\ & & d_4} .$$

*Pick any rational, orthogonal $4 \times 4$ matrix $Q \in SO(4, \Bbb Q)$.

*Form the rational matrix $Q D Q^{-1} = Q D Q^T$, and multiply by some positive multiple $m$ of the least common denominator of the entries of that matrix. By construction, the resulting matrix $A := m Q D Q^T$ is symmetric has integer entries and nonnegative eigenvalues $md_a$.


For example, consider the sequence $(2, 1, 1, 1)$ and for $Q$ take the above matrix given by the familiar Pythagorean triple $(a, b, c) = (3, 4, 5)$. Computing gives
$Q D Q^{-1} = \pmatrix{\frac{34}{25} & \frac{12}{25} \\ \frac{12}{25} & \frac{41}{25}} \oplus I_2$, and clearing denominators gives a matrix with the desired properties.
$$\pmatrix{34 & 12 & 0 & 0 \\ 12 & 41 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1} .$$
