Global variablesΒΆ

A simulation may use custom variables using the @variables keyword. We call these global variables to distinguish them from local phase variables.

Global variables can be useful if the same value occurs at several places in the script, and this value need to be changed. Then only one single change in the script is necessary. For example, if a script defines several @phase descriptions, and each has the same stop condition, this stop condition may include a global variable.

To set a global variable, use the @variables keyword:

@variables x=1, y=2

creates a variable x with value 1, and a variable y with value 2.

A variable name must be a valid name.

Variables can be used when setting values to parameters or other variables, for example:

@variables x = 10
n_subjects = 100 + x

It is possible to change the value of a variable (outside a @phase) by simply reassigning the new value:

@variables x = 10
n_subjects = 100 + x

x = 1
beta = x

The @variables keyword is only needed when initializing a global variable. You can change the value of a global variable after the @variables statement:

@variables x=1
...
x=2

Global variables can also be used in a phase block, but their value cannot be changed within a phase. Local phase variables can change values within a phase.

Note that the value of parameters do not work as variables: It is not possible to refer to a parameter to access its value, like it is possible with variables:

alpha_v = 0.5
alpha_w = alpha_v / 10  # Does not work
@variables alpha = 0.5
alpha_v = alpha
alpha_w = alpha / 10  # Works