
Dec 18th, 2017, 09:19 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Need help with formula
Hi,
I would very much love to get help with this issue I am struggeling with.
Basically it is a algorithm that takes a number (A) and outputs a result (B) (duh!), but unfortunately I suck at many things here in life, with math being one of those things...
Anyway, this is the case.
A maxValue = 100
A minValue = 1
A = 100 will always give the result B = 0.00
A = 1 will always give the result B = 0.25
A = 50 will output B = 0.125 etc etc...
Now, what I would like, is to know how to do those calculations, honestly I have no clue how to do this..

Dec 18th, 2017, 09:56 PM
#2
Hyperactive Member
Re: Need help with formula
Unfortunately, you've selected ranges and output values that are nonlinear (meaning the three points of reference you give don't result in a straight line). That is because 50 is not halfway between 1 and 100, but the value of B you've stated for A=50 is halfway between B(1) and B(100)
If you allow for a MinValue of 0, and say that when A=0 then B=0.25, then the equation to calculate B from A would simply be:
B(A) = A*0.0025  0.25
Which read out loud would be "The value of B at A is equal to A times zeropointzerozerotwofive minus zeropointtwofive"
You plug in 100 for A, you get 0 for B. You plug in 0 for A, you get 0.25 for B. You plug in 50 for A you get 0.125 for B.
To actually figure out the equation for this (showing work for how this the above equation was determined), there are many ways, but setting up a quick set of simultaneous linear equations is one way.
Using your input variable of A, and output variable of B, we want to end up with an equation of B = A*m + c. So we need to solve for m and c. Given the two sets of values of A and B that you've provided, namely A=100, B=0; and A=50, B=0.125, the two equations we can write are:
100*m + c = 0
50*m + c = 0.125
Where m is the slope of the line, and c is the unknown constant.
From these two equations, you should be able to see that we can subtract the second equation from the first equation to eliminate c, and get us to an equation where we can solve for m, namely:
50*m = 0.125
Divide both sides by 50, and we get our slope m = 0.0025
So, now that we know the slope, we plug our known value of m into one of the original equations (it doesn't matter which one) to calculate c:
100 * (0.0025) + c = 0
0.25 + c = 0
c = 0.25
So, that gives us the equation B = 0.0025 * A  0.25

Dec 18th, 2017, 10:43 PM
#3
Thread Starter
Hyperactive Member
Re: Need help with formula
Thank you so much for the solution plus the super description you provided
The min value can be 0, that is no problem, and I really didnt see that when I posted the question, but it is clear as the day now

Dec 19th, 2017, 08:31 AM
#4
Re: [RESOLVED] Need help with formula
This can be done without resort to simultaneous equations. The graph of B (y) against A (x) is a straight line so the gradient of any part of the line is the same. The equation of a straight line is y = mx + c where m is the gradient and c is y intercept. The gradient between any two points (x1, y1) and (x2, y2) on a line is given by (y1  y2) / (x1  x2). So in this case the gradient (m) is (0  (0.25)) / (100  50) which gives 0.0025. So we have 0 = 100 * 0.0025 + c which gives c as 0.25. So y = 0.0025x  0.25 or B = 0.0025 * A  0.25 as given in post #2.
All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/
C++17 Compiler: Microsoft VS2017 (15.7.5)
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
