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

Use this forum to post Vensim related questions.
Post Reply
oludot5
Member
Posts: 23
Joined: Thu Aug 16, 2012 12:01 pm
Vensim version: PLE+

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

Post 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
Rafael
Member
Posts: 21
Joined: Sat Aug 07, 2004 5:43 pm
Vensim version: DSS

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

Post by Rafael »

You should use a lookup. Look at the attached model.
Rafael
Attachments
ifthenelse.mdl
(1.62 KiB) Downloaded 710 times
Administrator
Super Administrator
Posts: 4626
Joined: Wed Mar 05, 2003 3:10 am

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

Post 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.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3816
Joined: Wed May 24, 2006 4:54 am

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

Post 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.
oludot5
Member
Posts: 23
Joined: Thu Aug 16, 2012 12:01 pm
Vensim version: PLE+

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

Post by oludot5 »

cheers guys, the lookup function does it well....
oludot5
Member
Posts: 23
Joined: Thu Aug 16, 2012 12:01 pm
Vensim version: PLE+

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

Post 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
tomfid
Administrator
Posts: 3816
Joined: Wed May 24, 2006 4:54 am

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

Post 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 )
oludot5
Member
Posts: 23
Joined: Thu Aug 16, 2012 12:01 pm
Vensim version: PLE+

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

Post 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
Attachments
example.mdl
(4.73 KiB) Downloaded 449 times
Administrator
Super Administrator
Posts: 4626
Joined: Wed Mar 05, 2003 3:10 am

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

Post by Administrator »

See the attached.

Tony.
Attachments
example.mdl
(4.95 KiB) Downloaded 509 times
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
oludot5
Member
Posts: 23
Joined: Thu Aug 16, 2012 12:01 pm
Vensim version: PLE+

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

Post by oludot5 »

cheers Tony
Post Reply