Forums > MaxMSP

Scaling and rounding in actual maths.

July 12, 2012 | 1:34 pm

Hey, so recently i’ve been thinking about a lot of the the max objects would be made using mathematical expressions or code, since i’m starting to look into other languages a bit more. Since my maths knowledge is a little awful, I thought i’d ask you guys.

Like I finally found out what [%] does and that it is the whole basis around the [counter] object.

So looking into [scale], I figured out that you take the input number, divide it by the high input value, and times it by the high output value, you get the same effect.
The only feature I can’t seem to replicate is the rounding used in the scale or round object – I can’t figure out what the raw maths equivalent os for
[round 1 @nearest 0] is.

I mean, in lots of code languages there is a round object/function/whatever, but I just want to know what is actually happening in the object.

Thanks guys!
Iyad.


July 12, 2012 | 1:54 pm

Ah. I think i’ve figured it out.

– Pasted Max Patch, click to expand. –

I was being stupid again.
ALTHOUGH, i’d love to know how any of the other max objects actually function through the land of maths if you guys have any examples.
This intrigues me.

Thanks.


July 12, 2012 | 10:50 pm

you could take a look into the helpfile of [mtof] to see what it does (but there are more than this one way how to calculate it)

here are a few other examples out of my abstractions (110.map is zmap or scale)

[attachment=199243,4173]

Attachments:
  1. actualmaths.jpg

July 17, 2012 | 2:36 am

Cool, thats for that, very helpull.

I was also wondering if [==], [< =] and [>=] could somehow be put into maths speak?

Perhaps the [>= 4] object would be along these lines?

[expr ($i1/4)/($i1/4)]

Thanks.


July 17, 2012 | 3:28 am

comparison operators can not be put to a lower level or something, it is kinda the
smallest possible part, almost machine language.

but expr can use these guys, too.

in expr it will take up more CPU than with the >= object, but of course, several of
them can be combined in one object that way, which can, otoh, also save some
CPU, at least when run in high priority (==when the input comes a from a metro or line)

[expr $i1>=4] will return 0 or 1, just like the >= operator external.

you can combine several comparisons using * as logical-and:

[expr ($i1>=4) * (($i1%12)==1)] will return true only if both conditions are met.

and of course you can combine it with any other functions.
use addition for the true and false version of the calculation, and multiplication
to bind them to the condition (==comparison operator).

[expr ($i1+5) * ($i1>=4) + ($i1) * ($i1<4)]

"take input and add five, but only when the input is greater or equal to 4, else output is input":

not even [if] can do that in one line.

-110


July 17, 2012 | 11:23 am

now the other way around! i mean, come on guys we should finally write the principia mathematica patch! :)

http://en.wikipedia.org/wiki/Principia_Mathematica


July 17, 2012 | 1:22 pm

Integration and derivation are pretty simple in a sample-based system, so you’re on the way… (+= and current-previous)

One C-style math that’s not available in expr (though it is in gen~) is floor/ceil. Floor always rounds towards negative infinity, and ceil always rounds up towards positive infinity. They’re handy for rounding algorithms because weird things happen with negative numbers. (Test your rounding code with negative numbers and you’ll see)

One other math that’s really good to know about is Horner’s rule for evaluating polynomials:

It’s way more efficient to do:
d + x*(c + x*(b + x*a)) // 3 multiplies, 3 adds
instead of:
a*x^3 + b*x^2 + c*x + d // 8 multiplies(!), 3 adds

On a practical note, it means that the number of operations to compute a polynomial grows linearly rather than exponentially, so you can compute a 10th order Chebyshev polynomial using 10 multiply-add operations, which is a good thing.


Viewing 7 posts - 1 through 7 (of 7 total)