Functions that are defined by interfaces in MOSAICmodeling can also be called “empty body functions”, because only inputs and outputs and no function bodies are specified inside these MOSAICmodeling functions. They can be used as placeholders in equation systems. The output and input variables must be defined via an interface whereas the mathematical expression doesn’t have to be specified at that point. In this way the equation system is independent from the functional correlation used to calculate the output variable. Similar to functions with defined bodies several variable inputs are possible while only one output variable is calculated. Both input and output variables can be scalars or vectors. Hence more than one functional dependence can be expressed by the use of one empty body function.

Problem description

In this exercise the use of functions defined by interfaces is practiced. An equation system with following mathematical operations will be created:

(1)

(2)

(3)

(4)

(5)

.

First an empty body function is created in MOSAICmodeling which will be filled with the mathematical expressions from equation (1) to (2) in *Matlab* afterwards. The function’s output variable is a vector. In the simulation shall be determined iteratively for a given and .

Exercise

- Create an interface similar to table (1). Use the notation 2951 (“Public_notation.mosnot”). The input variables are scalar while the output variable is a vector.
[table sort=”desc,asc”]

**Variable Naming**,**Dim**,**In/Out**

, Scalar, In

, Scalar, In

, Vector, Out

[/table] - Set up following equation:
referring to equation (5) and name it “eq_sumOfZ.mosequ”. Use the notation 2951 “Public_notation.mosnot” once again.

- Open the “Function” editor, enter a meaningful description and change the “Interface settings” to “Load Interface”. Select the interface that was created before. The notation from the interface is adopted. Save the function as “fun_emptyBdyFun.mosfun”.
- Build an equation system “eqs_calcValofY.moseqs” with a short description

and the notation 2951 “Public_notation.mosnot”. It has to contain the equation “eq_sumOfZ.mosequ” and the function “fun_emptyBdyFun.mosfun”. Use the same variable namings from the interface as applied namings for the function calls when editing the function calls. - Go to “Simulation”, load the equation system, set the maximum value in the “indexing” section to 4 and open the “Specification” tab. The degree of freedom should be 2. Select and as design variables and set the value of to 4, and the value of to 18. The initial value of can be 5.
- Next open the “Evaluation” tab, change the predefined “Language Specification” to “MATLAB NLE” and click on “Generate Code”. Change to the tab “View Code”, press the button “Export Code” and open a convenient output path, where a simulation folder containing the m-file is added to.
- Save the code as a function “solveEquationSystem.m” and open it in the
*Matlab*editor. - Search for the lines:

The number behind “fun_” equals the function ID in MOSAICmodeling. It differs from the one presented here. - Replace the lines from figure (1) by filling it with equation (1) to (4):

Save the changes. - Run the program, what is the result of y ? (Its value is displayed in the command window)