Application of Scalar Functions to Arrays


It is possible to apply a function to array values if an obvious generalization to element-wise application of the function is possible. Modelica functions with one scalar return value can be applied to arrays element-wise, e.g. if
v is a vector of reals, then sin(v) is a vector where each element is the result of applying the function sin to the corresponding element in v.


1 One Return Value


1.1 Simulation of OneReturnValue


Take a look at the value at time=0:





2 Returning More Values

Functions with more than one argument can be generalized to element-wise application. If more than one argument is generalized to an array, all of the arguments have to be of the same size, and they are traversed in parallel. This is the case in the example with the function atan2(x, y) below.






3 SumVec

Formal function parameters that are generalized to higher dimension arrays need not necessarily be scalars. For example, the function:

atan2SumVec(v1, v2) = atan2(sum(v1), sum(v2))

used below has two formal parameters v1 and v2 of type Real[:] computing atan2 on the sums of the argument vectors. Applying this function on a matrix which is a vector of vectors gives a result which is a vector. Calling this function with two matrices M1 and M2 as arguments gives the following result: