There are three broad categories of user-defined functions — Analytic,
Interpolation, and
Piecewise — and a number of templates for common function types, such as step and ramp functions. You can also create external function interfaces to include functions written in C and MATLAB
®. Functions can be global or local in a model component, although
external functions and
MATLAB functions can only be defined globally.
Function names for built-in mathematical functions such as abs,
cos, and
test are reserved function names, and naming a user-defined function using one of the reserved function names is not recommended because it can cause unexpected results. If the name that you type in the
Function name field is a reserved function name, the text color changes to orange, as a warning. If you move the cursor to a function name in orange, the tooltip
is a reserved name is displayed.
Click the Plot button (
) in the upper-right corner of the
Settings window to plot any user-defined function of 1–3 variables directly in a separate
Function Plot window.
Click the Create Plot button (
) in the upper-right corner of the
Settings window to create a persistent plot of the function under
Results, including a Grid dataset with the function as the source data, a plot group and a plot feature. The added nodes can be used for plotting multiple functions on top of each other or for direct comparison to model results, for example.
For analytic functions, first define a range for the arguments in the Plot Parameters section. Note that the range is expressed in the current unit system’s base unit corresponding to the set function argument unit. For example, if the current unit system is SI and the function argument unit is
cm, the plot range is expressed in
m.