# Use of Functions II – Applications Using Indices

On this page

This tutorial introduces the use of indices in function applications.

### Model description

The following example will solve the following equation system:

As in the previous example, a function shall be used to calculate . This function has the same formula as before:

### Workflow

#### Notation of equation system

For the notation of the equation, we need to set up all base names of symbols that appear in the equations, i.e.

• , parameter
• , parameter
• , parameter
• , parameter
• , additional value s (new)
• , iteration variable
• , iteration variable

As indices are now involved, we also need to define the index :

• , index of  1..N (new)

The resulting notation has ID 182662.

#### Equations

Next, we can define the equations of the model. Therefore, we open the equation editor, load the notation we just created, and enter the equations as stated above in the model description. The formulated equations are available with the IDs 182663 and 182664.

#### Notation and definition of function

Because we use exactly the same function, we do not have to define and save a notation and the function itself again, but we will simply re-use this function and apply it on our new variables. The function is available with ID 182656.

#### Equation system

We are now able to construct our new equation system based on the new equations and the function saved in the previous example:

1. Go to “Equation System” and load the notation for the equations
2. Add the two equations to your system in the Connected Elements tab
3. Go to the Functions tab. To use the general function created above, it must be added to the equation system and applied on the variables within this problem. In this context, applying means specifying which variable names in the equation system are supposed to be the corresponding input and output variables of the function.
4. Click on “Add Function” at the bottom of the screen and open your function in the opening popup window. After loading the function, you should see the expression for as a function of the inputs and . On the left hand side of the dialog, you see the Output Naming and the Input Naming as defined in the function.
5. On the right hand side of the dialog there is a section called Applications (Function Calls), which contains the tables Output Variable, Input Variables, and Parameters. Click on “Add Application”, which opens another popup window.
6. In this dialog, double click into the field Applied Naming or click on “Edit Output” below that field. This opens another dialog where you can enter the naming of the output variable in the equation system.
7. Enter into the Tex Expression, render, and confirm
8. Double click into the table row of the variable naming o or select this row and click “Edit Input”. Again a dialog is shown in which a variable naming can be entered. Enter , render, and confirm; then repeat this step for with being the applied input
9. Confirm these matches at the bottom of the window. When clicking on ‘A’ in the Applications, you should now find the match of the inputs (, )
10. Confirm in this window at the bottom and save your equation system

This equation system is available with ID 182665.

#### Evaluation / Simulation

Your model is now complete and you can move on to the “Simulation” section of MOSAICmodeling.

1. Enter a suitable description
2. Select the tab Equation System and load the system created in the previous steps. Go to Indexing and set to 2
3. If you now go to the tab Instantiated System and then to the Functions tab, you will notice that you still have one application but two usages, because the function is applied on all instances of , i.e., for and
4. Select the tab Specifications. In the list ALL VARIABLES, you will find the variables as defined in your model notation. Therein, will be of type “CALCULATED_VALUE” because it is determined by a function
5. Classify the variables and as design variables by selecting this category from the dropdown menu in the Type column. You can also assign the variables and as “ITERATION_VALUE”

### Initialization and results

This example is solved with the initial guesses for the variables and given in Table 1. After having assigned the initial guesses and the parameter values, you can save the variable specification and then the simulation. This simulation is available with ID 182666 with variable specification 182667. The solution for all iteration variables is also given in Table 1.