Matrix with each cell equal to sum of its adjacent cells

For sure such matrix could be found for $m \in 2\mathbb{N}+1, n \in 3\mathbb{N}+2$:

$$\left[\begin{matrix} a&a&0&-a&-a&0&a&a&0&\cdots & 0 & a &a & 0 &-a &-a\\ 0&0&0&0&0&0&0&0&0&\cdots&0&0&0&0&0&0\\ -a&-a&0&a&a&0&-a&-a&0&\cdots & 0 & -a &-a & 0 &a &a\\ 0&0&0&0&0&0&0&0&0&\cdots&0&0&0&0&0&0\\ \cdots&&&&&&&&&\cdots\\ 0&0&0&0&0&0&0&0&0&\cdots&0&0&0&0&0&0\\ a&a&0&-a&-a&0&a&a&0&\cdots & 0 & a &a & 0 &-a &-a\\ \end{matrix}\right]$$ Of course depending on the value of $n$ and $m$ last row and two last columns might be different (last row might start with $-a, -a$ and last columns might start with $a,a$), but general idea is the same.


The point of this answer is to show that the only solutions are Jaroslaw Matlak's solution (when $m \equiv 1 \bmod 2$ and $n \equiv 2 \bmod 3$), the transpose of his solution, and linear combinations of the above (when $m \equiv n \equiv 5 \bmod 6$).

Let's first avoid boundary effects by studying the problem on an $M \times N$ torus, so indices wrap around. Let $\phi$ be the linear map from $M \times N$ matrices which replaces each entry of the matrix with the sum of its $8$ neighbors. We want to understand the $1$-eigenspace of $\phi$.

In fact, it is easy to diagonalize $\phi$ completely. For any $0 \leq a < M$ and $0 \leq b < N$, the matrix $$A_{jk} = \exp\left( (2 \pi i) \left( \tfrac{aj}{M} + \tfrac{bk}{N} \right) \right)$$ is an eigenvector of $\phi$ with eigenvalue $(2 \cos \tfrac{a \pi}{M} + 1)(2 \cos \tfrac{b \pi}{N} + 1)-1$. That's $MN$ eigenvectors in an $MN$ dimensional vector space, and it is easy to show they are linearly independent. So we have found all the eigenvectors.

We want $$(2 \cos \tfrac{a \pi}{M} + 1)(2 \cos \tfrac{b \pi}{N} + 1)=2 \quad (\ast).$$ I will now show that the only solutions to $(\ast)$ in integers are $(\cos \tfrac{a \pi}{M}, \cos \tfrac{b \pi}{N}) = (1/2,0)$ and $=(0, 1/2)$.

Lemma Let $M > 6$. Then there is some $a$ with $M/4 < a < 3M/4$ and $\mathrm{GCD}(a,M)=1$.

Proof: We break into cases according to $M \bmod 4$. If $M$ is odd, $\tfrac{M-1}{2}$ does the trick. If $M \equiv 2 \bmod 4$, then $\tfrac{M-4}{2}$ works; if $M \equiv 0 \bmod 4$, then $\tfrac{M-2}{2}$ does. $\square$.

Now, suppose we have a solution to $(\ast)$ in lowest terms with $M>6$. The Galois group of $\mathbb{Q}(\cos \pi/M, \cos \pi/N)$ acts transitively on the values $\cos \tfrac{a \pi}{M}$ with $\mathrm{GCD}(a,M)=1$, so we can apply a Galois automorphism to make $a$ be as in the lemma, with $M/4 < a < 3M/4$.

But then $-1 < 2 \cos \tfrac{\pi a}{M} +1 < 0$, which means that $2 \cos \tfrac{\pi b}{N} +1 < -2$, an impossibility. We have a contradiction and deduce that $M \leq 6$; then we just check cases.

Finally, we need go from the torus case back to the rectangle. Given an $m \times n$ solution to the rectangular problem, we can build a $(2m+2) \times (2n+2)$ solution to the torus problem as shown in the example below for $(m,n) = (2,3)$.

$$\begin{bmatrix} u&v&w\\x&y&z \\ \end{bmatrix} \leadsto \begin{bmatrix} 0&0&0&0&0&0&0&0 \\ 0&u&v&w&0&-w&-v&-u \\ 0&x&y&z&0&-z&-y&-x \\ 0&0&0&0&0&0&0&0 \\ 0&-x&-y&-z&0&z&y&x \\ 0&-u&-v&-w&0&w&v&u \\ \end{bmatrix}.$$

So our previous solutions with $(\tfrac{a}{M}, \tfrac{b}{N}) = (\tfrac{1}{4}, \tfrac{1}{6})$ turn into $(\tfrac{a}{2m+2}, \tfrac{b}{2n+2}) = (\tfrac{1}{4}, \tfrac{1}{6})$ etcetera and, after a bit of cleaning up, we see that Jaroslaw Matlak has found them all.