﻿ 20-sim webhelp > Language Reference > Introduction > Equations

# Equations

The body of an equation model consists of the keywords initialequations, code, equations and finalequations, each followed by one or more equations. Equations are relations between variables indicated by an equal (=) sign:

y = x + 1;

z + y = sin(time*2*pi*f);

g = ddt(g + z, g_initial);

An equation can be combination of operators, functions, power-port variables, inputs and outputs (port names), constants, parameters and variables. Equations in 20-sim follow the standard mathematical notation.

## Rules

The following rules must be obeyed when specifying equations:

 1 An equation may span more than one line but must always be finished by a semicolon (;).
 2 Parentheses () may be used to indicate grouping as in ordinary mathematical notation, e.g.

u = sin(time*f*2*3.1415 + (a + b)/c );

 4 Extensions like .e or .f are used to indicate the effort and the flow variables of powerports. These extensions are not allowed for any other type of identifier (i.e. inputs, outputs, constants, parameters or variables).
 5 20-sim has some predefined variables which have a special meaning.
 6 Each variable must be assigned a value exactly once.
 7 Errors are shown automatically after checking in the Process tab. Double clicking on the error text will make 20-sim jump to the error, which is then colored red.

## Execution Order

 1 Equations within 20-sim may be entered in random order. During compilation, 20-sim will automatically try to rewrite equations into a correct order of execution.
 2 Some integration algorithms do more calculations before generating the next output value. These calculations are called minor steps, the output generation is called a major step. During a minor step, all model equations are executed. In most cases you will not notice this because only the results of the major step are shown in the simulator, but in some cases this may cause unwanted results.