Normalise rest of list

38 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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$

0
On

A general solution where you can have the ratio according to the array numbers. Let the 3 numbers in your array be : $x,\ y,\ z$

Condition 1: $$x+y+z = 1$$ where $y= \frac{1}{2}$

Condition 2:

You have scaled $y$ by ratio of $0.5$, let us scale the other 2 numbers by $\alpha$

$$\alpha x+ 0.25 + \alpha y = 1$$

So the 2 equations are:

$$x+z = \frac{1}{2}$$ $$\alpha x+\alpha z = \alpha(x+z) = \frac{3}{4} $$ $$\alpha = \frac{3\times2}{4}= \frac{3}{2}$$ Hope this helps...