Functions

A number of mathematical functions like abs, sqrt, mod, etc. are predefined in the Modelica language whereas others such as sin, cos, exp, etc. are available both in the language and in the Modelica standard math library Modelica.Math. The arithmetic operators +, -,*, / can be regarded as functions that are used through a convenient operator syntax. The body of a Modelica function is an algorithm section that contains procedural algorithmic code to be executed when the function is called. Formal parameters are specified using the input keyword, whereas results are denoted using the output keyword. This makes the syntax of function definitions quite close to Modelica block class definitions.

Modelica functions are mathematical functions (without global side-effects and with no memory). A Modelica function always returns the same results given the same arguments. Below we show the algorithmic code for polynomial evaluation in a function named
polynomialEvaluator.



1 Calling polynomialEvaluator

We can now call the function with the inputs and get the value of the output(s) back.