simple expr math

Jan 26, 2012 at 8:18pm

simple expr math

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:

– Pasted Max Patch, click to expand. –

but it’s a bit, erm what’s the word, grokky?

Brendan

#61474
Jan 26, 2012 at 8:56pm

see this post,

http://cycling74.com/forums/topic.php?id=37464

not as straightforward, but same idea should get you there.

* Hint you have 3 variables and 3 equations :)

#221796
Jan 26, 2012 at 9:32pm

Also a bit kludgey, but:

– Pasted Max Patch, click to expand. –
#221797
Jan 26, 2012 at 9:43pm

Here you go

– Pasted Max Patch, click to expand. –
#221798
Jan 26, 2012 at 9:50pm

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

#221799
Jan 26, 2012 at 10:38pm

it’s pretty much the simplest functional form that fits the criteria.

#221800
Jan 27, 2012 at 12:37am

big_pause: but how did you count the coefficients? That is indeed pretty awesome

#221801
Jan 27, 2012 at 6:24am

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).

#221802
Jan 27, 2012 at 6:35am

yea merkin math suxorz

#221803
Jan 27, 2012 at 10:54am

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.

#221804
Jan 27, 2012 at 11:43am

bp: this is awesome :)

#221805
Jan 27, 2012 at 8:09pm

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

http://cycling74.com/forums/topic.php?id=37464

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

– Pasted Max Patch, click to expand. –
#221806
Jan 27, 2012 at 11:42pm

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.

#221807
Jan 27, 2012 at 11:51pm

* waits for the punchline *

#221808
Jan 28, 2012 at 12:16am

punch and judy are off

#221809

You must be logged in to reply to this topic.