It is pretty common to need to be able to switch between alternative formulations based on some condition. The IF THEN ELSE function allows you to do this. It is implemented as a function in Vensim for two reasons. First, like other functions it returns a value. Second the statement
d = IF a THEN b ELSE c
actually assigns the variable "IF a THEN b ELSE c" to the variable d. In order for Vensim to differentiate variables from statements something such as :IF: a :THEN: b :ELSE: c would need to be used and this seems to create more distraction than it resolves. In Vensim this assignment takes the form
d = IF THEN ELSE(a,b,c)
Ø | With the Equation edit tool selected click on Change in Price. |
Ø | Click on the Functions tab then select IF THEN ELSE from the list and press Enter. |
Ø | Click on the Variables tab. |
Ø | Click on target price press the > key (or click on the More tab and click on the > button) then click on price. |
Ø | Double click on {ontrue} in the equation to highlight it. |
Ø | Hold down the Ctrl key and press Enter. |
Ø | Press the left parenthesis ( key, click on target price press the minus - key, click on price, press the right parenthesis ) key, press the divide / key then click on time to adjust price up. |
Ø | Double click on {onfalse} in the equation to highlight it. |
Ø | Hold down the Ctrl key and press Enter. |
Ø | Press the left parenthesis ( key, click on target price press the minus - key, click on price, press the right parenthesis ) key, press the divided / key then click on time to adjust price down. |
Your equation should read:
| IF THEN ELSE(price > target price, |
| (target price-price)/time to adjust price up, |
| (target price-price)/time to adjust price down) |
The function arguments appear in such a way that double clicking on them will allow you to replace them. Because the equation arguments are enclosed in Curly braces {} they are actually treated as comments and can even be left in, though this is rarely desirable. The use of Ctrl+Enter puts line breaks into the equations to keep them more readable.