﻿ 20-sim webhelp > Editor > Global Parameters and Variables > Global Parameters and Variables

# Global Parameters and Variables

Navigation:  Editor > Global Parameters and Variables >

# Global Parameters and Variables

Global parameters and variables are defined using the keyword global. In equation models, this keyword is added after the definition of the data type in the Equation Editor:

parameters

real global par1 = 100 {Hz};

real global par2 ;

variables

real global var1;

real global var2;

..

..

Parameters can only be assigned a value once. The same goes for variables. Only one submodel must defined their value using an equation. If parameters or variables are assigned more than once, 20-sim will generate an error.

## Example

The best way to describe the use of global parameters and variables is by an example model. You can find this model in the 20-sim demonstration library (Demo\Tips And Tricks\Global Parameters and Variables.emx). The model exists of three submodels. In the first submodel two global parameters (f and A) are assigned and one variable (sinewave). The variable is assigned a value in the equations section and connected with the output (out1).

submodel1

parameters

real global f = 100 {Hz};

real global A = 1 {none};

variables

real global sinewave;

equations

sinewave = A*sin(f*2*pi*time);

out1 = sinewave;

In the second submodel, the two global parameters are use to connect them with two outputs (out1 and out2).

submodel 2

parameters

real global f {Hz};

real global A {none};

variables

real global sinewave;

equations

out1 = f;

out2 = A;

In the third submodel, the global variable is connected with an output (out1).

submodel 3

variables

real global sinewave;

equations

out1 = sinewave;

To prevent conflicts global parameters may be assigned a default value only once. The same goes for global variables: they may be assigned a value in the equation section only once.