# exponential scaling problem

i have a value form 0 to 2047 and i want it to be scaled from 0.375 to 0.375 with 5 in the middle. so 0 to 1024 is scaled 0.375 to 5 and 1024 to 2047 is scaled 5 to 0.375.

the patch below shows what i made for this.

the problem is i want it to be exponentially scaled but i can’t scale it like i want with scales optional exponential value argument.

i want it exponentially scaled so that the middle of 0 to 1024 (512) is 1 and also the middle of 1024 to 2047 (1536) is 1.

is there a way of smoothly doing this?

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

*New From Clipboard*.

```
----------begin_max5_patcher----------
468.3oc2V98aBCBDG+41+JHj8nqofUqtrW1eGKlErEUVpTiEyby3+6CtVzpQ
aqN+w1dgKbbd226CTvUtN3goK4YXzSnWQNNqbcb.WFGNEycvSYKiRXYPX3QI
oxESwsxWZFSEMQHG+1bdjJOMDeO+VHZGvP7aCldd9nAE+FQLjnzgu+H0lmQo
RkjMkCq7xbAKwthtXBYBWAUmr0Y5Bk0KsTRxDeAIATQgFmyy3RESIRkkzY6d
fNCBLF+hgMhLO8pOmwyi1z2LEtEBOjIGiQCLgs100Lz5RgNZNyBaB5516Vvt
6BFr.nYbn+eUNH4ena.qFU7kP6iyhXIbcsoAd5CDAgdnNd5ilsC6TEx5lypf
bCsWUHKz+DQV2ChLxYgrKOp78JnE.IMsp8xIKlHzJwD4eBlDiPOLhfdFvDRM
gKg47jLNRWdpYV8LqvzsekLidW9Zz7g34gr3RB63OlAiAaFOTmSNg1iT2dew
51VWeMfl2k5NHBbhPt+a2PKX7uaKmktXdjsH1q.Pa6iXdlRHgWHKEDcmXlHh
i4vx1sgoh3YoBopPCGg+MVRlxQpQR6o6qtlZBlLu.cK0D422VWSjj4OrbqON
Uml1S3WaM0DLE9S15zSV69M1haKO
-----------end_max5_patcher-----------
```

Something like this! I found 2.321928 by working backwards (as you can see on the right side of the patch) rather than being clever and doing all the maths. Then it’s just a case of scaling the values to fit your input and output. You could probably do it all in one [expr] with clever use of ($f1>1024) but using split is much easier.

lh

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

*New From Clipboard*.

```
----------begin_max5_patcher----------
631.3ocyX01aaBCD9yjeEVn9g1IZFms4s8s86XsZhDbZ8FwfBNpYqp+2msAZ
ShZElFfgTjC9vj64d7cOmIOuvwcUwAVkK5anefbbddgiiwj1fSybG2soGVmm
VYVlqf8Twpe45UeKI6fzXdunLc8uQ9KUeZuYYpb8ibwC+bGasr1Gzvnk9dnP
e8XTndDqtFceyiH1ukKxYRiufFiaJDRQ5VlwQeeGOM28skWrW1tdbi0ZSx+T
xpcp6l7hToqW6Eu5M8ObE+ulkAXEXpMyyLdREl2R7c01dYwB8f2kwQJmmskU
Uonn.DdIACI33tIKRrdDHACKaAeDa0G9Am7Y3G01fBKcG4Pn1on3noNOYUp3
gdQCwiBMDfo5HOwTmjPl8rP3XlLTyBA9ydVfNfRFkoVqoBPrMhp3+KxD3AjS
XGJ2gJKd55q1.2cm2Uav27k.aHHpI2Av9yQFB9LLT1Qf5cBbhQ9fXDQqCdZm
ENsvD6Si6W3dVy0iBNXL18uVivaU4.27UvGSUYBssT6Hc.iwGUufq0XmY8Ug
nAjxpJy4RjORSSclsjznezQOWxPoyxEFUV8W8geBFkVM0T.PMsZiny8VM.Yj
jU6YEUCsUWPAwywCpBzQLgoNSY9ezjSDULOmaNWb96+YBSs8SIlph86V2BgF
MJOzawZFqRxEoRdg33EQNYQOxyxXl62Bus7rxBU0eCHvDXYvq8pUEhsSP2+t
6eVC1.ENft.aT+.6khI5HPfCAO0IlnSJlrJOKXZoIKfzzlLgsIYRcN7IESg1
hIX5vThEXh3Oo7zYt6C3I5ziotDLOaCdz26rorS+WpMkXBaClfK.SpIur3e.
NyJ8rC
-----------end_max5_patcher-----------
```

Or if you want it all in one go try:

[expr pow(((($f1>1024)*2048)-(($f1>1024)*2-1)*$f1)/1024,2.321928)*5.]

lh

i have abstractions for that, but they are not 100% perfect,

so they might have to be updated one day.

it is a bit complicated:

you first have to split the input range, then do the exponential scaling for both sides.

and for a maximum of security and flexibilty you should only

use > and < and pass/map the center number directly to the

new center value (this is the part which is currently not

done perfectly in my patches, the center comes out double.

this doesn matter when remoted from a GUI object, but it

starts to matter when you input gereric floating point numbers).

[110.makepow.mxb]

[110.makeexp.mxb]

[110.makelog.mxb]

[110.maketanh.mxb]

[110.makeexp-.mxb]

[110.makelog-.mxb]

[110.maketanh-.mxb]

[110.makeexp-bipolar.mxb]

[110.makelog-bipolar.mxb]

[110.maketanh-bipolar.mxb]

[110.makeexp-bipolar-.mxb]

[110.makelog-bipolar-.mxb]

[110.maketanh-bipolar-.mxb]

enjoy,

-110

…..

thanks lh, it works precisely like i want. but i don’t understand what’s happening in the expr objects, i’ve never done much with them.

could you please explain slowly what happens in the rightmost expr object of the patch your posted as well as the ones you used for the actual scaling? i would like to learn that so i can try using 8 or another value in the middle.

thanks for your abstractions roman but they look way too complicated for me, i have very little time so i can’t take time to figure them out.

i also would like to know what i should do tho get one more close to the middle. for instance instead of 1 @ 512, 1 @ 768.

I hate to bring up Litter Power again, but this is ridiculously easy to do with lp.scampf in any of its symmetry modes.

Create a [lp.scampf map 0 2047 5. 0.375 pow 1.] object, send it the message ‘sym 2′, and your values will map like the enclosed picture. Send a number to the last inlet (or edit the last argument) for a more or less steep curve. Use exp instead of pow for true exponential shapes (although most people actually want the power curves).

lp.scampf an lp.scampi are two of the most handy little utilities in the (free) Starter Pack, if I do say so myself. Max 5 doesn’t like the .help files in the Starter Pack a lot, but the objects themselves work on 5. The Pro Bundle is fully Max 5-compatible.

Hope this helps,

Peter

–

Edit: fixed silly typo, embedded image (didn’t know you could do that before!)

Right well if you have a simple [expr pow($f1,$f2)] and the base (first inlet) is limited to being between 0 and 1 then as long as the exponent (second inlet) is >0 the outlet will also always between 0 and 1 also.

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

*New From Clipboard*.

```
----------begin_max5_patcher----------
384.3oc0Tt1SBCCEF9yc+JZZ3CZxzzVTt3272gPLksNn5V6xVILkv+c6N6BB
Qj4EHZBYj9120y64Yms0dHxLSgLmfuC+.FgV6gPfTo.pdMhjHJBhE4fMhVtx
L6Ihe0VVYgEjkEoY3TypK5EwlLwuWD+xFOoBavBkd9iYx.aUo5Sul5iGBWYz
gk+wcKvSquE8xDkNVZgRxqEiLZqVjHg5celRDS1Z2rz13mUqVIYeIUVUTBo8
7KOpb0qvFLtq7UxpP3rc82UrAjRsMddkW76HbhhMtrbzFeLGZ+9edeyNZe6L
qRb0ysAssI1EF7CACWTEVhOlLSnm+kHC+6PlCL1jJd1Ec2uixraFALi8WbVg
dRlUFASI7A+imUFeBeIpBL2ROifwEyFqrVq+dzZmO4.2GIVo2+yy.PJ02Eg4
lkYAMQn5z7wagRnL2pzBqxnemG2j66MsPEFJg8osvIL0nz15Lfm9gOO6Zj1q
bGHSCNqYZbWwD67goN8ni+CvjawFu2fvuX8L
-----------end_max5_patcher-----------
```

In your case you we set the base to 0.5, this is because 512 is half of the range 0 to 1024. We also want the result to be 0.2 becuase 1 is a fifth of the range 0 to 5. I worked it out by setting the base to 0.5 and gradually increasing the exponent until the answer was 0.2.

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

*New From Clipboard*.

```
----------begin_max5_patcher----------
359.3oc0T00SCBCE84xuhlFePSPRKSYfu4uC2hoC5F0.sD3RF5x9uao.Nlej
g57Ae4B8v4x4dO2b6NGDYktQTQv2ge.iP6bPHKTK.p+Lhjyahy3UVZjXcdtP
AD2tuAhFnCOkq1HvPprBWq.Yl4UAVWCE0.1fQ87GxofCwoR0lGKEwPm19y8n
tXVfMFZe3S8n3k8onpykpLAXqAVO3ZsBT7bgU+6Kk7LxA5FkG3SGwuR9hkOy
2a.VlX+A5UOcsOoEZuiSavchNx5LsQuS1bgyZiyC8hhBnQ2bNaP+dzNH34BQ
mvskF2LpvjUlgC4MwlfQD9G5Dyh9O4DA+DmPI1ZR9CKIhlhRbgd6kTuaWrv8
h0rqNoaEvrKEz4m2kB1W4TeKygM1brIRxjp2eihs2ZwO1wpz0kwCx160t3C8
WhnBjJNH0pwjXGQJUljHTiWyykIEZoB5KB7xOc9M4ZhMkZJ7WTSlC6cdELLP
KEA
-----------end_max5_patcher-----------
```

If I was being clever and awake I would have worked it out using logarithms.

If a^b = c then b = log a of c.

(Either trust me or look it up in a textbook!) However we only have log10 available to use in [expr] so we use another rule of logarithms that states:

If b = log a of c then b = (log10 of c)/(log10 of a)

Put that in an [expr] where a=0.5 and c=0.2 and you get b=2.321928

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

*New From Clipboard*.

```
----------begin_max5_patcher----------
324.3ocqREsSCBCE84xWQSexkfHTGCz276vrXJPGqFnk.WhnK6eWZK3.iKio
9xMsmdt264bu8fChjn53MD7i3mwHzAGDx.oAPC2QjRVWZAqwPirqPIaKIt1m
pXP5dgL+kZdJXKS3ZOeWbzC5XbfNR887waGxnOYgrfClpEL.tSIAIqja5vS0
BVA4DcUKLxmNfZgf2q31dpUECHtXRBSlS9pY551H9vvJf1qEKrHyzHUxq2td
CQiczwQGbW3PHoE.k7hCg6CGs+RFBysZv4r5bGN0JQ+FqH4u0m7nU.dmwADd
WUMtPkeiuGc0c1CgqtniCizw.J8+cue1gwUspimNeLIRJDxu+823MM97gVip
sNcrsCkyEexeY7FPHYfn+ewDRalQZuHKiadeTekhrJkPBCh.u8GWgKVSQKQS
w+AM0e4nym.Zrf++
-----------end_max5_patcher-----------
```

Now we’ve calculated the exponent we just need to scale the input and output to get it into your desired range. This is where the /1024 and *5 come in. Put them all together and you get [expr pow($f1/1024,2.321928)*5.]. Simply change the scaling for when the input is >1024 and feed this half of the claculation using [split] and you arrive back at my orignal patch.

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

*New From Clipboard*.

```
----------begin_max5_patcher----------
447.3ocyUtsbBBCDF9Z3oHSldgsCZIAnn8t9bTc5fPTSGLgQhiz536dyAndn
sBTOLdSXxlMa92O1MYssEbLufjCAOCdEXYs11xRaRYvpbtEbdTQbZTt1MXBM
JE5XVHKRDOixl91BRrvDDO+dtN.rmZz2sZDLpbGrkyorThPGKTowb5mD0brq
e+s9wWJNzQiIwGYDygAmjxijGbUzoIZIxG+dWDTYZissZvog4FirRt2prSPJ
zIEjTjs.jwW0oiRgcuaB59GQtX+gCcv87vnA392+PPuiPELFqPAxcflNXCjp
ELS3LAKZtNagurXGx2P9rEMpPUwYjRL+jXgmQjkmkRE.WfBS0VszOzfiviSE
uVRE7eQEJS.cLeZCeB9O7QVgJUUsH.Y9DdlKLvGuwQBgwQroshBdWhFKYKUK
6nJwlogB0O3Vrgx+BVv7jNiCbu0qW16RE89foT1gO4nSSk88ASNe4h3JITdG
kCXatlPxETVjfxY65j2dNMiljPzqWIu4zjLtr6uTDXOTu.UKHR+bk22S.i90
+eMVrARcfpSrgsSrmpl7u..7bvoZ0j+UUSMpNK35hoFHoSoXRNYi8WfQgwTc
-----------end_max5_patcher-----------
```

And if you’re being really clever then use conditional operators in [expr] so that you don’t have to use [split] and two seperate scaling equations. I won’t explain this bit as I think what I have already is confusing enough.

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

*New From Clipboard*.

```
----------begin_max5_patcher----------
381.3ocyT0sSCBCF8Z3onowKjEF1VXByKLwmC2hoC51pAZIPWF5xd2kVfIy3
T1zXjK9HeG994bNPYmsEbgrhUBA2AdDXYsy1xx.oArZysfYzp3TZooL3xToX
SFzs4Q4TU7ZtX0SErXUyX7C7Pt.LZp9VnIgf7Pf4ssT2MWjxTlwgaAWJEJAM
iYVwCEbZJ78xkaTc0SZQafTujyZVplVTEzE.WPEqfGVldtk7WMUgI0boAlmX
VjbwyiCfZn8115f6.MAAaacucTTwpLZGxpxK.4xsWWec0R78XDIvYDAED4L9
HjwXmQ0oN2nymMyk34SvSIQNil38sVaTnN5GE86Zs3SYsmia5eItYRONcRUS
70w.TW7qEcGK0d+4o1lOjNL8dZCeIZafGWtchNNA8e+zRXeOvzGLkK93ePLx
TierwTJ2TD2Qglo4BdWpIrREWPUbonWM9GUyZdRBy73NxkwSxkbgpkBf4e5K
ogxH+Avnf+TFgG.iB+ALpNYu8aPKCF1j
-----------end_max5_patcher-----------
```

lh

thank very much you for explaining.

i don;t get everything you say but after looking up some things tomorrow (it’s quite late @ night over here) i probably will.

but what does the [expr pow($f1,$f2]actually mean? i figured out pow is something like ^ (don’t know how to call that in english) but it’s not the same. what does it actualy do?

and what does , mean?

It calculates powers: pow(a,b) The first number in the brackets is the base and the second is the exponent. In shorthand typing its usually shown as a^b which is "a to the power (of) b". For example:

4^2 is four squared which means 4×4 which is 16.

5^3 is five cubed which means 5x5x5 which is 125.

2^8 is two to the power 8 which means 2x2x2x2x2x2x2x2 which is 256.

And an inverse function:

64^(1/2) is the square root of 64 which is 8 because 8×8=64.

27^(1/3) is the cube root of 27 which is 3 because 3x3x3=27.

128^(1/7) is the seventh root of 128 which is 2 because 2x2x2x2x2x2x2=128.

It should be shown as I typed above: pow(a,b) but the comma is a reserved character in max so it has to be escaped with the backslash hence we get [expr pow(a,b)]. I hope that clears things up a bit better.

lh

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

*New From Clipboard*.

```
----------begin_max5_patcher----------
486.3oc0V00aBBCE8Y3WQSiOnILGszBxda+NllET5ztHEBTitY7+9rEXpaS7
KXi8xMo2daum6gSNz0lFvwwqXYPvCfm.FFqMMLzoTILJVa.iBVMYdPltLXDK
KKXJCZkumjsRpyivC.dkYSBjSlwESeNkMQle6XpSeaK.wUGwpHZPeavnhiHV
DwEyYRcWvEIeIVHEAQLcGdLkGLGtq73Exx5QEYySIeKgk2TH7y6WcUY720af
TsOOMOTe2wie8NjMTkaiooJXci7A1C3TEcfn6nCGRajNPWCcrEHiYoUL3HOe
0v5iTQpsJhsO1fitvAGerAmKjPK.bbfX5EwA35TR3R.3SyLsYIgyUIIXK2d3
uwFrUIofj3kc6vQCGZ0E0+9Nbbudmlgb0QD1qZwyeCEQpUSDvfpnCm8rTcv8
osNAiecRFzJMT8osbtvqQrSo+ibSo0oZnZuTpeKWMzfNoJWzSRMEdn1tsQOz
84F84fy4hu9LU8noxeHgkEuHcRYWKdVmEX23ExxjbQfjGK1uHxAEMiGFxz6W
BuHdXR7VceAHvtZQkqa9eoGTt.L5G+rd1XE0DXESZDr5z.X8VwD4bvD9WES9
mCjtLDgH6o9bqqOndM.PsIM.Pcpefdq5ty.Qza.QaWrw7CPIl1He
-----------end_max5_patcher-----------
```

that clears all up.

thank you very much for explaining everything so extensively!

Not a problem, I always find it a bit easier to learn from exploring examples rather than just reading the theory, especially with maths related stuff.

lh

nit wrote on Wed, 29 July 2009 01:50 |

but what does the [expr pow($f1,$f2]actually mean? i figured out pow is something like ^ (don’t know how to call that in english) but it’s not the same. what does it actualy do? and what does , mean? |

the main problem is that if you do not have the time to

find out what "pow" is (for example by entering it as

search term into google.com), you should give up doing

anything with a programming language asap.

this stuff really only works when you are willing to invest

some time.

i dont even have visited a highschool and i found out the

above methods by trial and error, i would exspect that from

anyone who is currently writing a project for his phd, too.

otherwise it is no wonder why there are so many professors

out there who dont know shite about their own topic.

i have a gig this friday and because i’m busy re-programming the core element of my patch (because there are some bugs in the old version caused by new funtions) and i came across more ‘trial and error’ then expected along the way i have still pretty much to do and therefore not much time.

telling me i should stop using a programming language because you assumed i’m lazy after reading a forum post is a bit lame.

nit wrote on Wed, 29 July 2009 03:44 |

i have a gig this friday and because i’m busy re-programming the core element of my patch |

i just thought that typing "pow" into google could have been

possible. but well.

you know what is good about expr? it has a lenght limit, so

noone must be afraid of too long formulas.

i just adopted tihfu´s idea to have comparison operators

inside the [expr] and implemented those and also the [mean]

of the input range into my formula from the [110.makeexp-bipolar] object.

the object now consists only of one single expression

and 4 default arguments.

this expression now reads like that:

[expr (((exp((($f1-$f2)/((($f2+$f3)/2.)-$f2))*log($f4))-1)/($f4-1)* ((($f2+$f3)/2.)-$f2))+$f2)*($f1< (($f2+$f3)/2.))+(((((exp(((( ($f1-(($f2+$f3)/2.))/($f3-(($f2+$f3)/2.)))*-1.)+1.)*log($f4)) -1)/($f4-1)*-1.)+1.)*($f3-(($f2+$f3)/2.)))+(($f2+$f3)/2.)) *($f1>(($f2+$f3)/2.))+($f1+0.)*($f1==(($f2+$f3)/2.))]

and guess what, the shit is too long, so you cannot write it like that in [expr], LOL!

now i have to split it somewhere, maybe it is enough to take

the means "(($f2+$f3)/2.))" out, we´ll see.

-110

.