### 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:

**all**of the following text. Then, in Max, select

*New From Clipboard*.

```
----------begin_max5_patcher----------
501.3ocyU10SyCBEG+5ZheGHb8rAnus4GDuwXLrV1jmmBrTnISM9cWdosqaS
m0oQ8hlS5gCG9e9wA34KuHBtTskogfqA2Bhhd15Ix6y4Ip2QDTP2VVS09.gk
JgfIMvYcCZXaMgAp4k+GrR0.nfLfp0rocWTqTRil+DyEIFGi58KaEbYMy3yM
djW676cOD7Fpo7Atb88MrRSP04jLax.DjKm.LAG9KFAta7RKoB+RCug0TQkz
Acwq7tUK+2UIIPuyWt7Bm0ZlMYnHXZMcM6Xnj94H.4sI.9jDH2WyAPjPhyrb
X9X.DRj4wMrvLfvy.NnyGNqpU1x4aoUfbBPjkSbDHME4LYni6DNBDVkQs8n.
3Rpb8YPEx7+9TIsv2WfS94nRwWfJsxRCWIgel5O8TGOPjP86MjT+gELJcZDn
+6.RLtXwCRsRInboWmncafM1o1kWTXsGuzzppMJtzn6iHGkkLGOKDqqcNdQQ
QVwB6DiQnB7hTua7Ptr+Bt6r4stlWwZ9.ZK5pp85Jm50SA9SBcd3buIYwjue
xsSz8Vx3UZzN.NYP98Gfro+.hDxHrlKO58NuncCb.mzp1lxdI0cGnG1C62Ls
gKo910cQ4jy3ndfWUwj68Nlfu2l9o19lr3b8ger3rWX8aHtCYx6Hth+xhC+k
Emyg075e3NAN
-----------end_max5_patcher-----------
```

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

Brendan

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

Also a bit kludgey, but:

**all**of the following text. Then, in Max, select

*New From Clipboard*.

```
----------begin_max5_patcher----------
528.3ocyU1rbaCBDG+rzSACmcz.BI619fzKsYxfkHIjQBz.nTmjIu6gOkUZi
crbayjKRhkkc+u+fE8TdFbqbGSCAeC7CPV1S4YYdSNCYwwYvd5tlNp16F75N
oXrGtJL00RgQyej4lBWVfhlsdvEcLieI3nwApo4Vt3lqTrFSHkUXhcMf50ew
+B4dVhKPfKiqg25Spb6cWrYdNEzdeNgemoZoBJbehkilTlKmxrx5ugothIna
67qLI0f6lGFXAI4JPpAtB.2RE2.AW5b647b2iUmHiDreYUbRSF1Ne4B0MzNF
nt.gAXTA.G+XIrb8QX4Fb.hqcuv03iAy5kCS7g.1+AFgKrXBfJr74eEdHgSW
I7DN3cH7T8oEOCcbS.OKgKj2kKUaBbo5n8fjyuG7v8YgONKJ0H66YByefItX
Xz31S.1zZ+zcT5mhn05Iq3hIiXzdq6aI63BVibTXlCw+x67pqK8.mD6SQoq9
dKfWtbfiNCNp63sLUJd15vWCKtzRmkv09RaseD4qyJM+dcfyyi0rJFSNd+0h
tKGNk3zFlULy3ieZ+t7u8OPew4r+ZnokiplTviMD.7TRZYZCWPMboXlO16ZA
6Ivs71VlXtpa4ZWgzd3MuSUMuNSusZ17golpOUpgbBpo5CSM3SQNjyTNgS0z
gg6YJcLjdkXa5uSpl9QoqQOLzGQnhcOO4eUtKZOm+BfFCfkY
-----------end_max5_patcher-----------
```

Here you go

**all**of the following text. Then, in Max, select

*New From Clipboard*.

```
----------begin_max5_patcher----------
408.3ocuT10aCBBEF9ZaR+OPH6h8gqQDqF2c6OwtYsoAUZKKVvfXpaM6+9Pb
1o8iL2pa2vw7xgCumG.2MdjELRTRygfG.OCrr1oUrLZUJVMBVvMjx3TRtIQ3
xTAuXCz9y4XIFUQzK26tWTTnRoJ0qYz5ZWsHhBZCfQD9JHXdShKEbUN6MSZH
2INM5YDU7ZFe0BIMVUWCWjuddcvoJL0L5pG+pXYDIYCUQkKnbRTpon6qn1yL
t1Tll.0d+45EY5gGkLRJr0BpaCyJbMpuOdTUTGrG.dE7mxKrqAQXOuV7BMj7
5IpLgvICNwxSYIT4oHFBedj0hRMDJrO.BgCLA+ZbE1aBo4igMS9NlUcVpsaV
gpidWbg903hS2pYydvnnkl8ARKyjfLw1quZIZ1La7Duo9XmfatU2nNXOe7c5
OBCvHuSh5dQ5e98QWuOCgG+.9BeidHBqKLLkwO5ebF+UMwAfMWTHia5ylabf
VVLglqXbhhI3sxxsaRqYIITdmKKIr7pKPF95b9i5A1Wn+ee0GaEbQ1BLe7Hc
3CfNX6Gh
-----------end_max5_patcher-----------
```

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

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

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

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

yea merkin math suxorz

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.

bp: this is awesome :)

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

**all**of the following text. Then, in Max, select

*New From Clipboard*.

```
----------begin_max5_patcher----------
647.3ocyWtsSiCCDF95fDuCVVbAc2PI14Tyd29b.HjaqaIroNQItPWP6695L
toDnsAygDYopZ2wSl96OOdryymdhCdZ9FdEF8KzUHGmmUVb.a0VbZL3fWw1L
KiUANhWwqpXK4X2sCJ4ajv.jw6rUvjytKUr71R9LoN79wdiCcQAgi8bQ9j59
jIi8P2z7LKxERAaEGh0uKSYY6BmX8pTQFWBBf1XMcN3Z9z6ufPZ6a9ZYiyj1
QuJ8IH5DpRCasq8U92BtVlXL5FXn+c5I0spF2uNZTS8NYihDwu.G52Lb7rc3
zEanp7Fu9BMI1MYHciFBID1REzGnYhcilvNISbDjyzKfI1xyY5d2TR+AlHau
LCRUFFQpaBpadmcWzDnjCwahtIFZ99pJaEzZQVt5uuKLj.SeeMEBgZwTu1Pn
fUpPfjWdKWvllApx6iRHxAHD8HDh9gIjZVxjXWDdJSr7qfKA+Qkx1O2huonD
Uj+34me1BxEmsfN5RUu.n20W6hxD0iDo9cHLRLzazkZ69u4IFM5G67A8Sjp4
8Wfn95iIiC1eExzEg3CrH3aEooGi6qEErY+AAasa+oy80D3vARD.Lhth3mCX
GJqM3H.K5ym0Zdm94.ETHTrTwUhA0MSlzmkMC6w7QsBwYoh8dmHXdVOvaPXU
95xYMQr4MQPslqy4UxTASllKZ4k+qc5tz4y4hWU3bdZUcwTXh6c7EUy0kmcp
qD6TVSrSYEamxJxNkkuIxhN3xRcBAJzDZEM3xJvDYEN3xx2DYEL3xhZhr7Gb
YQLQVzAWVFUffLrGJZhrBF7BDg8ur1dUGVQwC7xpsQVqH00BuOu7kqrhU2HS
+acjwk7GRadDekEHppu9ObKiVeL
-----------end_max5_patcher-----------
```

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.

* waits for the punchline *

punch and judy are off

Forums > MaxMSP