How to find an array of probabilities that give equal products I'm trying to figure out if there is an algorithm which can solve the following:
Given an array of randomly generated values, for example: $$[54.6, 1.96, 5.0, 31.31]$$
Find an array of equal length, in this example $[x_1, x_2, x_3, x_4]$ such that:
$$54.6 \cdot x_1=1.96\cdot x_2=5.0\cdot x_3= 31.31\cdot x_4$$
and
$$x_1 + x_2 + x_3 + x_4 = 1.0$$
Any suggestions for an algorithm to solve this?
Let the array be $a_1,\ldots,a_n$, which we assume are positive. The condition $a_i x_i = a_j x_j$ implies that
$$ x_i = \frac{a_n}{a_i} x_n. $$
Since the $x_i$ must sum to $1$,
$$
1 = \sum_{i=1}^n \frac{a_n}{a_i} x_n \Longrightarrow x_n = \frac{\frac{1}{a_n}}{\sum_{i=1}^n \frac{1}{a_i}}.
$$
The formula for $x_i$ shows that
$$
x_j = \frac{\frac{1}{a_j}}{\sum_{i=i}^n \frac{1}{a_i}}.
$$