How to make function with multiple branches?

Hi,

I want to create this function which has two different parts:

IF x < 0 THEN f(x) = 0
IF x between 0 and 0.1: f(x)=10*x
IF x > 0.1: f(x) = 1

What is the correct way to implement this in vvvv?

Thanks in advance,
Nuno

the generic way is using a switch with 3 inputs, and some logic which determines whether the switch should be set to input 0, 1 or 2.

that particular formula you can emulate very easy with one
Map (Value) node
set mode to clamp
set input max to 0.1
the other inputs already default to the right values.

Well, that is one off the hard parts for vvvv.

What I mostly do, is make some Boolean logic, put that in the mighty MultiFlipFlop (Animations) node, and the outcome off that to a Switch (Value). On that switch I connect the formulas I want to use.

How ever, what you want to do is also solved with the use of 1 node, the Map (Value) node.

I attached a partch, doing it both ways, hope it helps.

edit: Oschatchz beat me too it ;)

MultipleFunctions.v4p (17.4 kB)

hey west ;)

while i agree MultiFlipFlop is usually extremely helpful with switches, i guess in this particular case, the problem is much easier to solve with 2 comparisons and a + node.

actually i didnt expect it to be this simple before i tried it:
the patch below takes advantage of the fact that you can do additions on boolean values in vvvv.

you could even get rid of the two comparisons, by using a spread for the comparison values and a spectral +

MultipleFunctions.v4p (14.0 kB)

Thank you oschatz and West!!

Actually my function got more complex after all and I ended up using West’s patch which completely solved my problem! ;)

Thanks!
Nuno

Oschatz, you know what? Somehow the other day I didn’t see your second post with the improved MultipleFunctions patch.

Coool! I dropped the MultiFlipFlop ;) Thanks!

Nuno