Please enable JavaScript to view this site.

Vensim Help

Once a macro is defined, you can use it any number of times.  To use it, call it just like a function, separating the output list (if any) from the input list with a colon :.  When the macro is encountered, variables and equations will be made up so that causal tracing will continue to function properly.

Example

 

diddle[house] = daddle + SMOOTH(tadum[house],20)
~        blip/hour
~        Hey.
|

 

This uses the SMOOTH macro defined above, and is exactly the same as

 

diddle[house] = daddle + smooth tadum[house]
~        blip/hour
~        Hey.
|

 

smooth tadum[house]=integ( ( tadum[house] - smooth tadum[house] ) / 20
, tadum[house] )
~
~
|

 

except that in the case of the macro the name would be #diddle>SMOOTH#[house] instead of smooth tadum[house].Expanded macro variables are always enclosed within the hash sign #. This allows you to recognize immediately that you are dealing with a macro, and prevents conflicts with other variable names.

 

You can also get internally defined variables out of a macro. For example, here is a macro to calculate add three numbers. Internally we also calculate the min/max of the three numbers we are adding.

 

:MACRO: add3(val1, val2, val2 : minval, maxval )

 

add3 = val1 + val2 + val3
       val1
~
|

 

minval = min ( val1, min ( val2, val2 ) )
       val1
~
|

 

maxval = max ( val1, max ( val2, val2 ) )
       val1
~
|

 

:END OF MACRO:

 

 

To call the macro,

 

total reserve = add3( water reserve lakes, water reserve rivers, water reserve reservoir : min reserve, max reserve)
~        m*m*m
~
|

 

is water low flag = if then else ( min reserve < LOW WARNING LEVEL , 1 , 0 )
~        DMNL
~
|

 

is water high flag = if then else ( max reserve > HIGH WARNING LEVEL , 1 , 0 )
~        DMNL
~
|