Given the positive integer $N$ and $D$, generate all the non-negative integer matrices which satisfy
- matrix dimension is $N\times N$;
- sum of each row elements equals to $D$
- sum of each column elements equals to $D$
when $N\leq 5, D\leq 8$, there are how many matrices in each $\langle N,D\rangle $.
I post a summary of comments, since nobody wrote an answer.
Gerry Myerson:
This isn't so easy. There are research papers on the number of such matrices. For the given parameters, might be simplest just to bung it on a computer and count the matrices. This looks useful: Counting semi-magic squares from drvinceknight.blogspot.com. I did find a couple of other papers that should help:
The Stanley paper says, Let $H_n(r)$ denote the number of squares of side $n$, with nonnegative integral entries in each of the $n^2$ cells into which the square can be divided, such that every line-sum in the direction of an edge is $r$. The reviewer noted that $H_n(r)$ is a polynomial in $r$ of degree $d=(n-1)^2$ with rational coefficients, satisfying the relations $H_n(−t)=0$, $t=1,2,\dots,n−1$, and $H_n(r)=(−1)^dH_n(−n−r)$, $r\ge0$. If you can calculate the answers for some small values of $N,D$ then the Online Encyclopedia of Integer Sequences might have your answers.
Two more papers:
OEIS sequences oeis.org/A122751 and oeis.org/A002817 might be helpful.
user2468587:
I found this paper: The Ehrhart polynomial of the Birkhoff polytope, it told me how to get $H_n(t)$, it's really useful. In the same website, Ehrhart polynomials for $n =1, \dots , 9$ are given, that's amazing.