Given a pair of distributions $x,y\in(0,1]^{n\times 1}$, so that $1^Tx=1$ and $1^Ty=1$, 
I want to build a matrix $C$ (change matrix) that satisfy **at least** the following properties:


i) $C$ is diagonal if and only if $x=y$


ii) $C1 = x$


iii) $C^T1 = y$


iv) $C$ has nonnegative entries


How to build a $C$ that satisfy i)-iv)?


If $\Lambda\_x = diag(x)$ and $\Lambda\_y = diag(y)$ conditions ii) and iii) can be also written as:


(1) $C\Lambda\_y^{-1}y = x$ 


(2) $C^T\Lambda\_x^{-1}x = y$


respectivelly. Replacing (2) in (1) results in:


(3) $C\Lambda\_y^{-1}C^T\Lambda\_x^{-1}x = x$


And replacing $x$ by $\Lambda\_x1$ results the matricial Equation:


(4) $\(C\Lambda\_y^{-1}C^T-\Lambda\_x\)1 = 0$


or alternativelly (if 1 is replaced in 2), 


(5) $\(C^T\Lambda\_x^{-1}C-\Lambda\_y\)1 = 0$



Matrix decomposition problem
This is exactly the measure transportation problem in finite setting. Try to google "optimal measure transportation" for references and various algorithms. (ii) and (iii) are just the definition of transport (one also usually wants the entries of $C$ to be non-negative) and (i) is a very weak requirement of "optimality" that follows from any transport cost minimization requrement usually used (they are many and yield different answers).


