About User-Defined Functions
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 and calling Functions
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 text 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.
If you want to use a user-defined function in the model settings or for postprocessing, then call it with its arguments, such as func1(x,y) for a function with two arguments describing a spatial variation in a 2D geometry.
Plotting Functions
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 the Graphics window. This plot is temporary and disappears when you move to another Model Builder node making use of the Graphics 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 data set 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.