From a mxn matrix M with only strictly positive elements, I want to multiply each row and each column by real values in order to obtain a matrix N whose row sums are all 1/m and column sums are all 1/n.

For instance if n=m=2

$M=\begin{pmatrix} a&b \\\ c&d \end{pmatrix}$

then

$N=\begin{pmatrix} \lambda \alpha a & \lambda \beta b \\\ \mu \alpha c & \mu \beta d \end{pmatrix}$

and we want that $\lambda \alpha a + \lambda \beta b = \mu \alpha c + \mu \beta d = \lambda \alpha a + \mu \alpha c = \lambda \beta b + \mu \beta d = 0.5$

In general, We see that we have m+n variables with m+n-1 non-linear equations. (the equations over rows give the sum of all elements of the matrix as the equations over columns). So we can set the value of one of the coefficient (eg : $\lambda=1$ in the previous example)

I can easily find the result for m=n=2 and I imagine that the resolution practicly feasible but I would like to find a general formula whatever would be m or n.

Any help would be welcome.