Please enable JavaScript to view this site.

Vensim Help

If you ask to have one or more arguments passed as Vectors you can choose to modify values.  And you can also choose whether or not to tell Vensim that you are going to do this.  In general, the modification of values is not likely to cause difficulty, though you do need to be cautious about modifying Level values, especially if you want to use an integration technique other then Euler Integration.  There is, however, one thing that can really mess up and that is computational sequence.

If you write the equations:

a = x

x = 1+Time*0

y = f1(x)

z = x

Vensim reorders them for execution to the order:

x = 1+Time*0

a = x

y = f1(x)

z = x

You would expect a = 1 and z = 1.  However, if f1 modifies the value of x (say setting it to 0), z will be 0, and a will be 1. The algorithm that Vensim uses to order equations for execution fails when external functions can change values at will.  If f1 is marked as modifying values then Vensim will reorder these equations as follows:

x = 1+Time*0

y = f1(x)

a = x

z = x

Thus both a and z will be 0.  

Marking functions as modifying values is not, unfortunately always enough.  Suppose that you have two functions, f1 and f2 marked as modifying values.  Then the equations

x = 1+Time*0

a = f2(x)

y = f1(x)

z = x

will be executed in precisely this order.  If f2 does not actually change x but just return its value and f1 sets the value to zero we will again get the erroneous result a = 1 and z = 0.

The long and short of this discussion is that functions that modify values can give unpredictable results.  Even from this example it should be clear that there is no "correct" ordering algorithm.  If functions that modify values are used in a controlled manner with clear thought given to the computational implications they can be quite useful, but they are dangerous.  Whenever possible, use the User Loops approach instead.