Please enable JavaScript to view this site.

Vensim Help

Navigation: Reference Guide > The Vensim Modeling Language > Equations

Equation Format and Conventions

Scroll Prev Top Next More

Vensim uses standard algebraic expressions with the same rules for precedence as those used by JAVA, DYNAMO, C, BASIC and other common languages.  Vensim also supports standard mathematical functions and has additional functions that make writing equations faster and simpler.  Every equation has a field for the units of measure and for a short description of the variable on the left as in:

profit = revenue - cost

~$/year

~The profit of our company. |

If you include the units of measure and description, you can take advantage of Vensim's on-line documentation and units-checking capabilities.

In addition to the units of measure, you can include the range that is allowable or definitionally possible for a variable, as in:

cost = fixed cost + variable cost

~ $/year [0,500E6]

~ The total cost of operations.  

|

During simulation any variable that goes outside of its range will be flagged with a warning message.

Increment

You can include the increment by adding a third number in the range as in:

Time to adjust workforce

~ Month [1,30,.5]

~ The time to adjust the workforce up and down.  

|

The increment specified is only used for constants to determine the amount of change in response to slider movements when SyntheSim is active.  You can make the increment the same as the full range as in

Switch for quality correction

~ Dmnl [0,1,1]

~ Switch to indicate that speed is adjusted when quality changes.  

|

This will cause the slider in SyntheSim to have only two positions (on/off).

Supplementary

You can also mark a variable as supplementary in order to suppress the USE FLAG messages.  When working with the Equation Editor, you mark a variable as supplementary by clicking on the supplementary checkbox.  In the Text Editor, you can mark a variable as supplementary by using the :SUP flag after the comment.

Examples

Spacing and line breaks are ignored within equations (except that line breaks are not allowed within a variable name as described above).  You can include comments in an equation by enclosing them in paired braces { }.    The examples below illustrate some different formats for defining equation information.

Example 1 (Best Practice)

sales = salesmen * sales productivity

~ $/year [0,1.0E6]

~ Dollar volume of sales.

|

Quick and Dirty

sales = salesmen * sales productivity~~|

No units or comment.  It is always recommended that you include units.

Redundant Definition

Sometimes when variables are subscripted, you need to write more than one equation, because some or all of the subscripts require a separate equation.  Because  comments and units are associated with variable names, not with equations, you only need to fill in the units and comment once.  In the Equation Editor this is automatically taken care of for you.  In the Text Editor you will need to end all but one equation with a ~~| or simply a |.  If more then one set of comments or units is specified for a variable you will receive a warning message, and only the first will be used.

population[AgeGroup1] = INTEG(births – deaths[AgeGroup1] – aging[AgeGroup1],init population[AgeGroup1])~~|

population[AgeOlder] = INTEG(aging[AgeYounger]-deaths[AgeOlder]-aging[AgeOlder],init population[AgeOlder])
~ Rabbit
~ The population of rabbits – births only add to the first cohort 

|

{comments}

 

unit cost = ( 1 + interest rate )
       * ( investment / ( 1 - tax rate ) + operating cost -
        tax rate * depreciation / (1-tax rate) )/
       {Formulation provided by

 John Jackson (phone: 2-3433)}

( ( 1 + interest rate ) *
       quantity produced )

~ $ / unit

~ unit cost of product built up from definitions used by the company cost accountants.

|

Example 2 illustrates an equation format that uses spacing and multiple lines to make a complicated equation as transparent as possible.  You can place braces { } anywhere inside of an equation.  Vensim ignores everything appearing within the braces when the equation is read in.  Comments within braces will appear in text view and model documentation, and in the Equation Editor if they are embedded in the expression for a variable.