Increasing/decreasing a set of numbers in proportion to match a total

I haven't done much maths for 30 years. I have extensively Googled for a couple of hours but can't seem to find what I need.

I have a set of numbers (here's five of them but there's around 50 in total):

• 20 Red Widgets
• 30 Blue Widgets
• 45 Yellow Doodahs
• 50 Green Wotsits
• 20 Cyan Thingies

The total of these numbers is 165.

I need to increase/decrease these numbers to total 300 instead of 165 for an export to a portal, but do it in proportion to each other. So, I want the same proportion of Red Widgets to Yellow Doodahs in the export.

I feel it has to do with ratios but every ratio tutorial starts with the known ratios whereas I think I need to figure out what the ratios are first.

I am trying to script this in a database programme.

• Not sure I understand what is desired. Does this work for you: if the numbers are $\{a_i\}_{i=1}^n$ then multiply each number by $\frac {1000}{S}$ where $S=a_1+a_2+\cdots a_n$ is the sum of your numbers.
– lulu
Commented Dec 11, 2019 at 10:57
• I'm afraid that I don't know the notation. I'm really looking for a dunce explanation. I spent time on the question to hopefully be as clear and concise as possible, but I'll try editing it again. Commented Dec 11, 2019 at 11:31
• Notation? "Take your numbers and add them up. That gets you some result we'll just call $S$. Now compute $\frac {1000}S$. Call it $R$. Multiply every one of your original numbers by $R$. The new list of numbers will sum to $1000$."
– lulu
Commented Dec 11, 2019 at 11:34

Say your list is $$\{a_i\}_{i=1}^n=\{a_1,a_2, \cdots, a_n\}$$.

Let $$S$$ be the sum of your terms, so $$S=a_1+a_2+\cdots + a_n$$ and let $$R=\frac {1000}{S}$$.

Now make a new list as $$A_i=R\times a_n$$.

This does the job since the sum of the $$A_i$$ is $$R$$ times the sum of the $$a_i$$ and that comes to $$1000$$ by the definition of $$R$$: $$A_1+A_2+\cdots +A_n=R\times a_1+R\times a_2+\cdots + R\times A_n=$$$$=R\times (a_1+a_2+\cdots +a_n)=R\times S=1000$$ Clearly the ratios work the way you want since $$\frac {A_i}{A_j}=\frac {R\times a_i}{R\times a_j}=\frac {a_i}{a_j}$$

Example: if your list was $$\{20, 30, 45, 50, 20\}$$ then $$S= 165, R= 6.\overline {06}$$ and your new list is $$\{121.\overline {21}, 181.\overline {81}, 272.\overline {72}, 303.\overline {03}, 121.\overline {21}\}$$ where, as usual, the bar means that the digits are repeated. Thus $$\frac 1{11}=.09090909...=.\overline {09}$$ for instance.

The two basic facts you need to know are the following:

• If you multiply two numbers by the same "scaling factor", their ratio stays the same. For example, the ratios "$$10:3$$", "$$20:6$$", "$$30:9$$" and "$$100:30$$" are all the same. (In fact, their ratio will stay the same "only if" you multiply them by the same number. If you multiply them by different numbers, the ratio will change).
• If you have a bunch of numbers and you know their sum, if you make a new bunch of numbers by multiplying them all by some "scaling factor", the sum of the new numbers is the sum of the old numbers times the scaling factor. For example, the sum of $$4$$, $$6$$, $$7$$ is $$17$$, and the sum of $$12$$, $$18$$, $$21$$ is $$51$$, which is $$3 \times 17$$.

These really do just sort of come from a certain familiarity with maths, and it can be hard for mathematicians on the internet to empathise with people that aren't mathematicians, so I appreciate that you've had a hard time Googling!

So suppose you have your set of numbers: $$20$$, $$30$$, $$45$$, $$50$$, $$20$$, totalling $$165$$.

For the purposes of this discussion, I will "simplify" your quantities - I never said you had to multiply by a whole number, so I'm going to multiply by $$\frac 15$$!$${}^{\text{No jokes about \Gamma please}}$$

We now have the numbers $$4$$, $$6$$, $$9$$, $$10$$, $$4$$, totalling $$33$$. (These are "simple" because I can't divide them by anything else while keeping them all intact)

We want to make their sum be $$300$$. Unfortunately, this isn't possible! That's because $$300$$ is not a multiple of $$33$$. We have two options now - we can keep their ratios completely correct, but not quite make the right sum. We could make the sum $$297$$ or $$330$$, which are the two closest multiples of $$33$$ to $$300$$. (We'd do this by multiplying by $$9$$ or $$10$$, respectively). Here it's really your call if you'd rather over-shoot or under-shoot.

Alternatively, we could try and get the sum exactly by just multiplying by $$300/33$$, leaving us with some non-whole numbers. At this point you'd have to round all your numbers somehow. You could round them all up, or down, or to the nearest integer.

If you want the total to be exactly $$300$$ (or whatever number), there are a number of approaches and really it becomes more of a programming job. See for example the techniques described at https://stackoverflow.com/questions/13483430/how-to-make-rounded-percentages-add-up-to-100.

If it's easier for you to see it in code, here's a simple Python program exhibitively implementing two of the approaches I mentioned:

from functools import reduce
from math import gcd

numbers = [20, 30, 45, 50, 20]

def make_sum1(numbers, n):
"""
Return a list of numbers in the same ratios as numbers, but with sum
approximately n.
"""
num_gcd = reduce(gcd, numbers)
simplified_numbers = [number // num_gcd for number in numbers]
simplified_sum = sum(simplified_numbers)
return [number * (n // simplified_sum) for number in simplified_numbers]

def make_sum2(numbers, n):
"""
Alternative approach by rounding down
"""
num_sum = sum(numbers)
return [number * n // num_sum for number in numbers]

print(make_sum1(numbers, 300))
print(make_sum2(numbers, 300))


Interestingly they both give the same answer because your numbers are so small. If you add a big number (like $$100$$) to the list, the results will be different.