Quandaries
and Queries 

Hi, I want to know if is it possible to solve this problem: I have an empty NxM matrix and I know totals (sum) by rows and totals by column. Is there any algorithm to fill the matrix so that the summary of columns and rows gives the original values I have? Thanks Marcelo 

Hi Marcelo, If you just have the row and column sums there may be more than one matrix with those sums. For example
and
have the same row and column sums. Also you can't just take and numbers to be the row sums and column sums, since the sum of the row sums, and the sum of the column sums, must be the same. In either case you have the sum of all the entries in the matrix. I talked to a couple of people here who know a lot more about matrices than I do. They told me that you can do something if you know that the matrix is composed of zeros and ones. Suppose that you start with a matrix of zeros and ones, for example
The row sums are 1,1,2 and the column sums are 1,2,1. I am going to produce other matrices with the same row and column sums. The technique is the following
So in the original matrix I see
so I construct the new matrix
Also in the original matrix I see
so I construct the new matrix
In this matrix I see
so I construct the new matrix
Finally in this matrix I see
so I construct the new matrix
All five of these matrices have row sums 1,1,2 and column sums 1,2,1. The interesting fact here is that these are the only 33, zeroone matrices with these row and column sums. Harley 

