Link to home
Start Free TrialLog in
Avatar of skij
skijFlag for Canada

asked on

Decrease number proportionately

x is a number between 1 and 30.

If y is 50 then x should remain as it is.

If y is smaller than 50 or larger than 50, the x should be proportionately decreased.

For example, if x is 25 and y is 20 then x should be decreased to about 10 and if x is 25 and y is 2 then x should be decreased to about 1.

What is a mathematical formula that could be used for this?
Avatar of Enabbar Ocap
Enabbar Ocap
Flag of Italy image

X=x (y/50)
Ah, that could increase x above 30 if y was over 50. Did you want to always reduce x by the proportion that y was away from 50?
Avatar of skij

ASKER

Yes, I want to always reduce x by the proportion that y is away from 50.  

For example, x should get smaller if y is less than 50 but it should also get smaller if it is greater than 50.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Enabbar Ocap
Enabbar Ocap
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Basically it finds the ratio of y from 50, squares it and roots it to make it always positive, then subtracts that proportion of x from itself.
Avatar of phoffric
phoffric

What are the acceptable values of y? From your question, I gather that the final result must be in the range [1,30] inclusive. I do not understand something about the accepted equation:

>> X=x-(x * sqrt (((50-y)/50)^2))
To make it easier for me to read:
 X =  x   -   x * abs(50-y)/50

Suppose x = 3 and y = 15, then
X = 3 - 3 * (50 - 15)/50 = 3 - 3 * 35/50 = 3 - 2.1 = 0.9
which is outside the range.

If x = 3 and y = 7, then we get further out of range --> x = 0.42
Yes that does put x below 1.
I don't think the use of abs is acceptable as the requirement was for a mathematical solution, not a programming one which would have been simpler and cleaner.
Could perhaps keep x above 1 by moving a term of x/29 into the right hand side and adding 1 to the result.
It's messy already and that would make it worse.
So much simpler if a spreadsheet formula was required.
>> I don't think the use of abs is acceptable as the requirement was for a mathematical solution
In mathematics, the absolute value or modulus |x| of a real number x is the non-negative value of x without regard to its sign. Namely, |x| = x for a positive x, |x| = −x for a negative x (in which case −x is positive), and |0| = 0. For example, the absolute value of 3 is 3, and the absolute value of −3 is also 3. The absolute value of a number may be thought of as its distance from zero.
https://en.wikipedia.org/wiki/Absolute_value

|x| is a continuous, piecewise differentiable function of x.
A function is piecewise differentiable or piecewise continuously differentiable if each piece is differentiable throughout its subdomain, even though the whole function may not be differentiable at the points between the pieces.
https://en.wikipedia.org/wiki/Piecewise
I just wanted to make sure that the author was ok with some combinations of x and y resulting in X going below 1.
Thanks for pointing it out. I had missed that detail in the question.
If the formula is adjusted to keep the value above 1 it won't be exactly the proportional reduction expected. X would only reduce in 29ths not 30ths. It rather depends on the requirements behind the question.

Interesting about abs, I never met it until I was writing a computer program. It is a useful tool, but to me it seems like a cheat instead of a function. Possibly invented for use in statistics, which would hint at the shakey grounds that they are based on.
In the OP: "If y is smaller than 50 or larger than 50".
If y is, say 9999, then we expect the final result to be 1; but the accepted solution puts X out of bounds.

Based on the OP question, y is not restricted, and x is restricted to be in closed interval [1,30].
This question should be reopened to meet the OP question criteria.

If anyone has a solution, then put it down, and I will see to it that it gets credit. If not, then I will take a stab at it later this week.
If I'm allowed abs, perhaps I can use Floor() as well?
I'll look at an alternative later.
This is going to either need some bounds for y, or a different interpretation of how the reduction is done.
Above I have used the examples in the question, if y is half of 50 then reduce x to 50%, if y is a fifth of 50 then reduce x to 20%.
For values of y above 50 this works fine up to 100. If y is half again as big, 75, then reduce x to 50% etc.
But what is ecpected to happen to x if y is a larger multiple, say 500? Y has increased by 10 times so does x reduce to a tenth of its size? This doesn't balance with y being 5 which would also reduce x to a tenth.
You would have a very slewed graph.
If y is bound between 0 and 100 and x between 1 and 30 then:
X=(x-((x-1)*sqrt (((50-y)/50)^2)))

Will need a more detailed definition to deal with y >100 or y <0
@Thibault St john Cholmondeley-ffeatherstonehaugh the 2nd

>> x is a number between 1 and 30.
It doesn't say that x is an integer. Did you intend that X is an integer? If so, then don't you have an implicit floor already in your formula?

>> if y is a larger multiple, say 550
then difference is 500, and 50/500 = 1/10th.

>> does x reduce to a tenth of its size?
Sounds reasonable as long as you get the bounds right (i.e., X >= 1).

The author emphasized his requirement:
>> I want to always reduce x by the proportion that y is away from 50.  
>>x should get smaller if y is less than 50 but it should also get smaller if it is greater than 50.

I do not see any limits on y in either the OP or this clarification.
My formula above does not assume either x or y are integers, it keeps x between 1 an 30.
I don't see any mention of limits for y, but without limits, positive or negative, what value should be used to calculate the proportion? 50 is only a meaningful value if the lower limit is zero, or another specified value. A graph with 0 as a lower limit and an infinite upper limit would result in a steep curve for y between 0 and 50, and a very shallow parabola for values above 50.
This doesn't sound useful.
I think the original question related to getting the absolute value of the difference of y from 50. We don't know why the lower limit of x was 1, or if these are real values. It may be a question just to find a method which can be applied to some other ranges of values entirely.
Without further explanation from the asker we can't guess what might be sensible limits for the values.
Avatar of skij

ASKER

Thank you for your additional input and ideas.  

I have posted a related question here:
https://www.experts-exchange.com/questions/28953209/Adjust-number-proportionately.html
Rushing out so no time to evaluate the new question in detail. Off hand, it looks like this question with some clarifications. I put in a RA to let mods look at this and make a decision.
Avatar of skij

ASKER

The discussion that followed me selecting an answer was unrelated to the original question, which is why I posted a new question.  An answer has already been provided for this question and there is no need to re-open this question.  The new question is related but different.  Thank you everyone for your help.  There is no need for this question to be re-opened.
Other members who search and find this question may think that the answer is correct even though, for unrestricted y, and for X restricted in the closed interval [1,30], the answer is not correct. We try to keep the PAQ with answers that comply with the original question.

For this reason, I believe this question should be reopened so that an accepted answer matches the OP.

I agree that your other question is not a duplicate of this one.
Are you agreeing that my second formula with the description is a better answer to this question, or are you going to redefine the question and await a better answer?
Is my second equation adequate?
Do I need to work on another solution?