This tutorial introduces the use of indices in function appliances. It is recommended that you work through the previous tutorial first.

Equation system

Equations

(1) $latex x_{i} = a_{i} + b_{i}$

(2) $latex s_{i} = y_{i}$

Function

(3) $latex y_{i} = 0.5 \cdot (a_{i}+b_{i})$

Notation ‘nota x’

Base Names:

[table sort=”desc,asc”]

Name, Description

$latex a$,parameter a

$latex A$,parameter A

$latex b$,parameter b

$latex B$,parameter B

$latex s$,additional value s (new)

$latex x$,value x

$latex y$,value y

[/table]

Indices:

[table sort=”desc,asc”]

Name, Description

$latex i$,index of $latex x$ 1..N (new)

[/table]

Problem description

Maximum value:

$latex N = 2$

Design variables and the corresponding values

$latex a_{i=1} = 1.0$

$latex a_{i=2} = 1.5$

$latex b_{i=1} = 3.0$

$latex b_{i=2} = 3.5$

Iteration variables and initialization values

$latex s_{i=1}=0.0$

$latex s_{i=2}=0.0$

$latex x_{i=1}=0.0$

$latex x_{i=2}=0.0$

Expected results

$latex s_{i=1}=2.0$

$latex s_{i=2}=2.25$

$latex x_{i=1}=4.0$

$latex x_{i=2}=5.0$

The following general function will be used:

Function ‘mean value’

(4) $latex m(o,p) = 0.5 \cdot (o+p)$

Notation ‘nota mean value’

Base Names:

[table sort=”desc,asc”]

Name, Description

$latex m$,mean value

$latex o$,value one

$latex p$,value two

[/table]

**Creating the equations** The equations are created as usual (see section *Basics*). The basic work flow for this is:

- Create and store the notation as it is given above for the equations. If you have just done the tutorial part
*Use of Functions I*you may extend the equation you created there and use it here. Otherwise, create a new notation and enter the symbols specified below ‘nota_x’ into it. - Create and store the equations (1) and (2) using the above notation.

**Creating the function **First the general function (4) must be created. This general function will be used to reflect relation (3). If you have done the tutorial part *Use of Functions I* you may use the function created there. Otherwise follow the instructions given there to create the function.

**Creating the equation system** For detailed help see section Basics. The basic work flow is:

- Add the notation, here you should use the same notation as you did for the equations (‘nota x’).
- Add the equations created in the previous steps.

**Adding and applying the function** To use the general function created above, it must be added to the equation system and applied to the variables concerned. In this context, applying means specifying which variable names in the equation system are supposed to be the corresponding input and output variables. In this example the applied variables contain indices. MOSAICmodeling can deal with indexed expressions and during the evaluation of the equation system the function is applied for every instance of the index.

- Open the Equation System in the Model Bar.
- Activate the tab
and press**Functions****[Add Function]** - Take a look at the new dialog window named
.**Add Function Usage** - In this dialog press
on the upper right hand side and choose the function you created and stored during the previous steps. The field**[Select]**should now display the function (4).**Preview** - On the left hand side of the dialog you see the
and the**Output Naming**as they are defined in the function. The latter are will be linked to the desired variable names as they appear in the equation system, the so called**Input Namings***applied namings*. - On the right hand side of the dialog there is a section called
that contains the tables**Applications (Function Calls)**,**Output Variable**, and**Input Variables****Parameters.** - Press
to create a new function application.**[Add Application]** - Take a look at the new dialog window called
**Edit Function Appliance** - In this dialog double click the field
or click**Applied Naming**below that field. This opens another dialog where you can enter the naming of the output variable in the equation system.**[Edit Output]** - Enter y_{i} into the
area and press**Tex Expression**and then**[Render]**.**[OK]** - Double click into the table row of the variable naming o or select this row and click
. Again a dialog is shown where a variable naming can be entered.**[Edit Input]** - Enter a_{i} into the
area and press**Tex Expression**and then**[Render]**.**[OK]** - In the same way specify b_{i} as the applied naming for p.
- Press
in the**[OK]**dialog.**Edit Function Appliance** - In the
dialog the new function appliance should now be shown in the tables in the**Edit Function Usage**section.**Applications** - Press
in the**[OK]**dialog.**Edit Function Usage** - Save the equation system.

**Evaluating the equation system**

- Go to the
Bar.**Simulation** - Select the tab
and load the equation system created in the previous steps.**Equation System** - In the tab
specify the index maximum value for i as 2 (by entering it into the cell**Indexing**).**Max Val** - Activate the tab
. You will see four equations in the sub tab**Instantiated System**, two of which contain instances of $latex y_{i}$. Although it is not explicitly visible here, the function has been applied according to the indices to each set of $latex y_{i}$, $latex a_{i}$ and $latex b_{i}$.**Equations** - Go to the sub tab
and select the function on the left hand side to display the function applications on the right hand side. As you can see, the function calculates the value for two different variables ($latex y_{i=1}$, $latex y_{i=2}$) based on the one application for $latex y_{i}$, that has been specified in the equation system editor.**Functions** - Select the tab
and then**Specification**. You will find that the variables named $latex y_{i=1}$ and $latex y_{i=2}$ have been automatically classified as**Variable Specification***calculated variables*. - Manually classify the variables $latex a_{i=1}$, $latex a_{i=2}$, $latex b_{i=1}$ and $latex b_{i=2}$ as design variables by moving them into the corresponding table and give them the values specified in the problem description indicated in the beginning of this section.
- Save the variable specification list
- Enter a description
- Save the evaluation/simulation
- Open the tab
, click**Evaluation**and then**[Generate Code]**.**[Evaluate]** - Have a look at the output of the solver given in the tab
.**Results**