Suppose we are given a probability distribution over a finite discrete product space $p(x,y)$ with marginals $p(x), p(y) > 0$ for each $x,y$ respectively. We are given two more marginal distributions $r(x), r(y)>0,$ for each $x,y$ respectively. Can we always find functions $f(x), g(y)$ such that 


$\sum\_y p(x,y)f(x)g(y) = r(x)$


$\sum\_x p(x,y)f(x)g(y) = r(y)$?


It appears that we should always be able to do this, but I would like an explicit expression for a solution $f,g$ in terms of $r(x), r(y).$ Thanks.



Joint distribution with specified marginals
This is called the generalized matrix scaling problem and several other names. Both the theory and associated algorithmic problems have been studied. I suggest you start with [this paper](http://link.springer.com/article/10.1007/s10107-006-0021-4) and the papers it cites.


