I have an list of fractions as such:
sum(3/10, 1/2, 1/5) = 1
and I multiply some element (the second in this case) by some known factor (1/2 here):
sum(3/10, 1/4, 1/5) != 1
So the answer would be:
sum(????, 1/4, ???) == 1, where arr[0] and arr[2] are proportionate to their original values.
How can I normalise the rest of the array, so that the array still sums to 1, but the second element remains the same (1/4 in this case) and the rest of the elements are proportionately changed? I've tried adding/multiplying the rest of the elements by the factor but it doesn't work.
Suppose the changed number has initial value $k$ and has been multiplied by a factor $a$.
Then the sum is now $k(a)+(1-k)$. In particular this differs from $1$ by $k(1-a)$.
So to set the sum to $1$ again, only allowing to multiply all the other numbers by a constant factor, we need to multiply by $$\frac{k(1-a)+(1-k)}{(1-k)}=\frac{1-ak}{1-k}$$
Sanity-checking, for your question we have $k=a=1/2$. The formula then gives $3/2$
The formula works for all combinations of inputs as long as $k\neq 1$