[page is WIP]
User Functions allow you to take 1 or more arguments and return a new result. This can be done via a graphical or table lookup, where a single argument is looked up on the table and interpolated to a result. It can also be done via a programatic definition, like in a programming language, where the arguments are manipulated to return a new result. This allows you to encapsulate some tricky or repeated logic for use in your model.
If the formula of a Function is left blank, then the Function will take a single argument, which will be looked up against the table. The graph can be sketched on to quickly define a rough lookup table, or you can use the table input tab to define it more precisely or from a spreadsheet source.
The Min and Max X will define the range that the table will cover, and the Step will define the interval between points in that table. For instance, 0 -> 10 with step 1 would have points at 0, 1, 2... 10, where 0 -> 1 with step 0.1 would have points at 0, 0.1, 0.2... 1. If the argument falls outside of the range, then it will clamp to the closest end of the table.
Programatic functions are very much like Variables, in that they have a formula that defines their result. However, unlike variables they may not refer to the rest of the model, and may only refer to their arguments. Arguments are detected implicitly from the formula. Any undeclared local variable will be treated as an expected argument (see Formulae for information on local variables).
A very simple function definition (with name "My Function" for this example) would be one that doubles its input:
@x * 2. This can then be used in another formula by passing it an
x as argument like so:
"My Function"(2). The name of the argument can be any valid local variable identifier, such that
@my_input * 2,
@some_value * 2 etc. all function the same way, and are called in the same manner.
Arguments can be freely referred to multiple times.
For a single argument, Sysdea will show a computed curve to show the behaviour of your function between a Min and Max X. However, arguments outside of this range will still be calculated, and not clamped. For 2 or more arguments, Sysdea does not currently offer any visualisation.
When you have multiple arguments, the order of the arguments comes from the order in which they appear in the formula.
@x - @y would be called as
"My Function"(x, y) whereas
@y - @x would be called as
"My Function"(y, x).