Is it possible to solve for values in a matrix such that all rows and columns have equal sum?

546 Views Asked by At

Is it possible to solve for values in a grid such that all rows have the same sum and all columns have the same sum where values in the table can be any real number?

meaning:

A B C D = x
E F G H = x
I J K L = x
M N O P = x
= = = =
y y y y

A+B+C+D=x  A+D+G+K=y
E+F+G+H=x  B+F+J+N=Y

I have developed a brute force genetic solver to find very near to correct values but I have to believe there is a better solution out there.

Many Thanks

3

There are 3 best solutions below

4
On

A solution to this problem will only exist when $x = y$.

To see this, note that the sum of all entries in the matrix must be equal to both $4x$ and to $4y$, hence $4x = 4y$, hence $x = y$.

1
On

I am not sure if I was entirely clear, but here is one of the results that I was able to acheive from the brute force evolutionary solver I developed.

A B C D E        .6570  .7448   .7009   .7448   .6570  =  3.5045
F G H I J        .7448  .6570   .7009   .6570   .7448  =  3.5045
K L M N O        .7009  .7009   .7009   .7009   .7009  =  3.5045
P Q R S T        .7009  .7009   .7009   .7009   .7009  =  3.5045
U V W X Y        .7448  .6570   .7009   .6570   .7448  =  3.5045
Z @ $ % ^        .6570  .7448   .7009   .7448   .6570  =  3.5045
                   =       =       =       =       =
                 4.2054  4.2054  4.2054  4.2054  4.2054

Where values of inputs are fixed as A=E=Z=^
                                    B=D=F=J=U=Y=@=% etc, 

While similar results are acheived with all unique possible inputs things are simplified to speed up the solver.

I am just wondering if there is any other way to achieve the same results in a more elegant fashion. I am noticing some interesting patterns emerging so I have to guess there might be a set of equations to solve for inputs given desired outputs. However, I am only an architect with some math coding and math experience, no specific expertise in these realms.

Best

0
On

A permutation matrix is a 0, 1 square matrix with a single 1 in each row and in each column. Clearly, all the row sums and all the column sums of a permutation matrix are 1. Now if $P_1,P_2,\dots,P_r$ are permutation matrices, and $c_1,c_2,\dots,c_r$ are any real numbers, then $$c_1P_1+c_2P_2+\cdots+c_rP_r$$ has the property that every row sum and every column sum is $c_1+c_2+\cdots+c_r$. So this lets you construct as many of these matrices as you'd like.

What's more, it can be proved that every square matrix with all row sums and all column sums equal can be written as such a linear combination of permutation matrices, so this construction doesn't just get lots of matrices, it gets all of them.