0
$\begingroup$

What mathematical formulation that can help me to generate all possible (N x N) matrices where the sum of all elements inside each matrix equal constant number M ? Note that: M > N If it can be solved using combinations and permutations, how can I formulate it ?

$\endgroup$
  • 1
    $\begingroup$ I assume you're looking for nonnegative integer entries.With the requirements here there's no need to think of matrices. This is the number of partitions of $M$ into $N^2$ parts, allowing $0$'s. I don't think there's an easy way to count those. See en.wikipedia.org/wiki/Partition_(number_theory) $\endgroup$ – Ethan Bolker Aug 14 '18 at 16:37
  • $\begingroup$ How can I calculate all possible partitions of M into N^2 elements ? $\endgroup$ – WASEL Team Aug 14 '18 at 16:41
  • $\begingroup$ As I said in my comment, there is no easy way to do that. You can start at the wikipedia page to study the question. If $M$ isn't too large a brute force recursive computer program will do the job. $\endgroup$ – Ethan Bolker Aug 14 '18 at 16:45
  • 1
    $\begingroup$ @EthanBolker: if order matters, and it seems to here, we are looking for compositions. The number of those is easy $\endgroup$ – Ross Millikan Aug 14 '18 at 18:44
1
$\begingroup$

If the positions of the matrix are distinct you are looking for weak compositions of $M$ into $N^2$ pieces. There are ${M+N^2-1 \choose N^2-1}$ of them. The Wikipedia article derives this.

$\endgroup$
  • $\begingroup$ I didn't mean the numbers in the matrix had to be different, just that you care where the numbers go in the matrix. For example, $\begin {pmatrix}1&2\\3&2 \end {pmatrix}$ is different from $\begin {pmatrix}2&1\\3&2 \end {pmatrix}$ $\endgroup$ – Ross Millikan Aug 14 '18 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.