How to keep numbers within an average without them being all the same

90 Views Asked by At

Background: I am developing an app to make calculations for worldbuiding, following the instructions given by the YouTube channel Artifexian. In one of the videos, he mentions a formula to keep the eccentricities of the orbits in check. The video in question I'm now working on is this one.

If I want to keep an average of, say, 5, my numbers could be: 9, 1, 3, 7, 10, 0, 4, 6, 5. This were hand picked, but what if the average must be 0.085 like in the video? The app can set in advance how many planets the system will have, so I know what the average eccentricity should be, but how can I set random eccentricity values while keeping that average. Is there a math way to do it?

I'm posting this question here because I think it is more related to math than to worldbuiding or science.

Edit: the average eccentricity for 2 planets should be 0.254; for 3, 0.156; 4, 0.111; 6, 0.068; 7, 0.057 and for 8, 0.048.

2

There are 2 best solutions below

0
On

The average of a set of numbers depends only on how many numbers there are, and on their sum. Thus, if you want ten numbers, with an average of $0.085$, you simply need to ensure that their sum is $10\times 0.085=0.85$.

In order to get that total, just pick the first nine choices without their sum going over $0.85$, and then make the tenth number equal to $0.85$ minus the first nine.

Another approach would be to start with all of the numbers the same – equal to your desired average – and then start modifying them in a way that preserves their sum, and therefore also preserves their average. For instance, subtract a small quantity from one of the eccentricities, and add the same quantity to another one. You can do this as many times as you like, until your numbers are sufficiently non-uniform.

0
On

Well, the simplest way is to pick n-1 random number, then solve for what the nth number must be. But that makes the last one vary wildly.

The average is a linear constraint; if the average and count are both fixed, then you have $x_1+x_2+... = n\bar x$, where $n$ is the count and $\bar x$ is the average. This defines a n-1 dimensional hyperplane. If n=5, then it's a four dimensional space in five dimensional space.

It might be easier to visualize in three dimensional space. Then any set of numbers for which the average is $0.085$ has to be on the plane $x_1+x_2+x_3= 0.255$. You probably have further constraints that you want to incorporate. If you want all of the numbers have to be within some range (for instance, between 0 and 1), then the mathematical name for this is a simplex (this n-dimensional version of a pyramid). You can do a search on "random sample from a simplex". I found this: https://cs.stackexchange.com/questions/3227/uniform-sampling-from-a-simplex