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
Function to create Multiple "IF...ELSE" statements
Re: Function to create Multiple "IF...ELSE" statements
You should use a lookup. Look at the attached model.
Rafael
Rafael
- Attachments
-
- ifthenelse.mdl
- (1.62 KiB) Downloaded 710 times
-
- Super Administrator
- Posts: 4626
- Joined: Wed Mar 05, 2003 3:10 am
Re: Function to create Multiple "IF...ELSE" statements
There are a number of ways.
1. You can nest the IF THEN ELSE statements
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
This is my preferred method if you have to do something like this.
3. Use a lookup if b, c or d are constants.
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 ) )
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 )
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Function to create Multiple "IF...ELSE" statements
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.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Function to create Multiple "IF...ELSE" statements
cheers guys, the lookup function does it well....
Re: Function to create Multiple "IF...ELSE" statements
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
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
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 )
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 )
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Function to create Multiple "IF...ELSE" statements
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
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 450 times
-
- Super Administrator
- Posts: 4626
- Joined: Wed Mar 05, 2003 3:10 am
Re: Function to create Multiple "IF...ELSE" statements
See the attached.
Tony.
Tony.
- Attachments
-
- example.mdl
- (4.95 KiB) Downloaded 510 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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559