We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a bit of a math problem and I can't seem to find an easy solution.
I want to make a function that easily changes the other values in the array if one value of that array changes. (Mathematically something like this (X+Y+Z = 1) And I can think of two versions of this problem/function but I can't find a neat solution for any of them.
One solution is that if I change one value, all the other values have to change too so it doesn't exceed or go below 1 (for example I have (0.3, 0.3, 0.4) and I change the first value to 0.2 the difference gets split over the other two values resulting in (0.2, 0.35, 0.45).
Another solution could be that I specify which value is linked to another value (so only two values are linked, or more if I have more than three values in the array) (for example if I have (0.3, 0.3, 0.4) and I say that the first two values are "linked" , when I then change the first value to 0.2 I get (0.2, 0.4, 0.4).
This looks like a easy problem but I can't find a simple solution. I want to be able to change the size of the array later on without changing the programming.
Does anyone have an idea? Or a mathematical formula that solves this easily? What would be very neat is if I could specify the relation between different values in the array so if one changes I can give a percentage of how much the other values are linked and need to change (for example 0% is no link so no change, 100% is a 1on1 link so if one value changes the other changes equally)
This must be something simple but I can't seem to wrap my head around it. Thanks.
Answers
My idea is to create a
class
to tightly control the add() & sub() processes! Here's my draft: :>Thanks, I definitely like the idea for an add and subtracts method, I will work on it a bit more with your code as a base to fit it in my program.