## simple expr math

Jan 26 2012 | 8:18 pm
Hi brain not working
how can i achieve the following, preferably with expr input: 1, output 0.1 input: 5, output 1. input: 10, output 10.
I mean, this would do:
but it's a bit, erm what's the word, grokky?
Brendan

• Jan 26 2012 | 8:56 pm
see this post,
not as straightforward, but same idea should get you there.
* Hint you have 3 variables and 3 equations :)
• Jan 26 2012 | 9:32 pm
Also a bit kludgey, but:
• Jan 26 2012 | 9:43 pm
Here you go
• Jan 26 2012 | 9:50 pm
Thanks chums
Chris - split, of course!
big_pause - I saw that thread too, but ran screaming from the equations, thanks for filling in the blanks - ps how the hell did you arrive at that function?? Give me your brain - NOW, mwah ha ha
2 excellent solutions (3 if you count mine LOL)
Brendan
• Jan 26 2012 | 10:38 pm
it's pretty much the simplest functional form that fits the criteria.
• Jan 27 2012 | 12:37 am
big_pause: but how did you count the coefficients? That is indeed pretty awesome
• Jan 27 2012 | 6:24 am
whenever you have 3 points you can go with quadratic equation (the expression big_pause estimated) by that substitution algo from school (at least in germany).
• Jan 27 2012 | 6:35 am
yea merkin math suxorz
• Jan 27 2012 | 10:54 am
xidance pretty much has it
given the choice of function
y = a + bx^c
and
y = 0.1, x = 1 y = 1, x = 5 y = 10, x = 10
gives us 3 equations
0.1 = a + b*1^c = a + b => a = 0.1 - b [1] 1 = a + b*5^c [2] 10 = a + b*10^c [3]
substituting [1] into [2] (you could sub into [3] here, doesn't matter)
1 = 0.1 - b + b*5^c 0.9 + b = b*5^c
take logs of both sides, to give an expression for c in terms of b
ln(0.9 + b) = ln(b*5^c) ln(0.9 + b) = ln(b) c*ln(5) c = (ln(0.9 + b) - ln(b)) / ln(5) [4]
then, substituting [1] and [4] into [3], lets us find b
10 = 0.1 - b + b*10^((ln(0.9 + b) - ln(b)) / ln(5)) 0 = -9.9 - b + b*10^((ln(0.9 + b) - ln(b)) / ln(5))
at this stage I just ran through a quick hacked python script to find b (life's too short)
once you have b, you can use [1] to get a, then either [2] or [3] to get c.
yes, I'm a nerd.
• Jan 27 2012 | 11:43 am
bp: this is awesome :)
• Jan 27 2012 | 8:09 pm
so, I thought about this a little more. We can transform our linear inputs to this, and get the same problem as in the 'other' post
here's what we do. we have as our inputs (x's) that need mapping, [1, 5, 10].
we shift this down to [0, 4, 9], then normalise to [0, 4/9, 1], or algorithmically
[x1, x2, x3] -> [(x1-x1)/(x3-x1), (x2-x1)/(x3-x1), (x3-x1)/(x3-x1)] = [x1', x2', x3'] and these map = [y1, y2, y3]
we now have a similar problem as in the post above, and can get the solution to
y = a + b*x'^c : where x' = (x - x1)/(x3 - x1)
for our new mappings (both for this case, and general algorithm)
we have, for x1 = 1, x1' = 0, y = 0.1
a = 0.1 or y1
for x3 = 10, x3' = 1, y = 10
y3 = 10 = a + b => b = 9.9 or y3 - y1
and solving for x2 = 4, x2' = 4/9
1 = 0.1 + 9.9*(4/9)^c 0.9/9.9 = (4/9)^c c = ln(0.9/9.9)/ln(4/9)
or y2 = y1 + (y3 - y1)*x2'^c c = ln((y2 - y1)/(y3 - y1))/ln(x2')
so for our specific case, we can write
y = 0.1 + 9.9*x'^{ln(0.9/9.9)/ln(4/9)} y = 0.1 + 9.9*[(x - 1)/9]^{ln(0.9/9.9)/ln(4/9)}
and for the general case
y = y1 + (y3 - y1)*x'^{ln((y2 - y1)/(y3 - y1))/ln(x2')}
with x' = (x - x1)/(x3 - x1) and x2' = (x2 - x1)/(x3 - x1)
as before.
and we can chuck this straight in an single expr - happy days
• Jan 27 2012 | 11:42 pm
to find a ln or exp expression starting from 3 points - except when they are variables - you could also just try manually which coefficient matches.
• Jan 27 2012 | 11:51 pm
* waits for the punchline *
• Jan 28 2012 | 12:16 am
punch and judy are off