Page 1 of 1

Function to create Multiple "IF...ELSE" statements

Posted: Sun Nov 04, 2012 1:00 am
by oludot5
Hi,
I am building a model with a variable, say X, with a function to take a value of various multipliers depending on the range of its input.e.g if X input 0.8-1, X output = 1,if X input is 0.6 - 0.79, X output = 0.8...so this is more or less like a "switch" statement.Can I do this in Vensim please.I tried the "IF" function but it only takes an argument..
Thanks

Re: Function to create Multiple "IF...ELSE" statements

Posted: Mon Nov 05, 2012 9:05 am
by Rafael
You should use a lookup. Look at the attached model.
Rafael

Re: Function to create Multiple "IF...ELSE" statements

Posted: Mon Nov 05, 2012 9:09 am
by Administrator
There are a number of ways.

1. You can nest the IF THEN ELSE statements

Code: Select all

result = IF THEN ELSE ( a > 0 , b , IF THEN ELSE ( a > 0.5 , c , 0 ) )
I personally don't like nesting IF THEN ELSE statements, it makes it difficult to read and debug what is happening.

2. Add IF THEN ELSE statements

Code: Select all

result = 
IF THEN ELSE ( a >= 0 :AND: a < 0.5 , b , 0 )
+ IF THEN ELSE ( a >= 0.5 :AND: a < 1 , c , 0 )
+ IF THEN ELSE ( a >= 1 :AND: a < 1.5 , d , 0 )
This is my preferred method if you have to do something like this.

3. Use a lookup if b, c or d are constants.

Re: Function to create Multiple "IF...ELSE" statements

Posted: Mon Nov 05, 2012 9:01 pm
by tomfid
Also, for most kinds of strategic simulation, you'll be dealing with systems that are not well-described by discrete logic like IF THEN ELSE. Continuous functions will be more desirable. There's a nice article about this somewhere, but I can't think of the citation at the moment. Forrester wrote about it in Industrial Dynamics, I think.

Re: Function to create Multiple "IF...ELSE" statements

Posted: Tue Nov 06, 2012 9:52 am
by oludot5
cheers guys, the lookup function does it well....

Re: Function to create Multiple "IF...ELSE" statements

Posted: Wed Nov 14, 2012 2:34 am
by oludot5
hi guys,

So, i have a variable "age"as an input into the lookup variable that accepts the age variables and produces other figures depending on the age value entered. As I have completed the lookup values in the equation box, there is no place to represent "age" as the input in the equation box and vensim notifies me of an error as it is an expected input but I have not used the input "age" in the equation.

Thanks

Re: Function to create Multiple "IF...ELSE" statements

Posted: Wed Nov 14, 2012 3:17 am
by tomfid
That happens in a separate equation.

First, define your lookup shape (sounds like you've already done that).

Then, use the lookup in an equation, e.g.

price of cheese = normal cheese price * cheese inventory effect on price lookup( cheese inventory/normal inventory )

Re: Function to create Multiple "IF...ELSE" statements

Posted: Wed Nov 14, 2012 9:47 am
by oludot5
Hi,
Still not clear, so in the attached example, the variable "lookup" is suppose to accept input Design quality an output"average manpower to maintain test suite". The relationship between these two has been described in the lookup.Where does the "Design quality" fit into the equation box of the "lookup variable"?Are you saying I create another variable?

Thanks

Re: Function to create Multiple "IF...ELSE" statements

Posted: Wed Nov 14, 2012 10:45 am
by Administrator
See the attached.

Tony.

Re: Function to create Multiple "IF...ELSE" statements

Posted: Fri Nov 16, 2012 1:59 am
by oludot5
cheers Tony