How to write multiple condition with IF THEN ELSE?
I am using a shadow variable TIME. the pseudocode:
IF TIME=0, TIME=1,..,TIME=8 ---> true=1.28
ELSE 0.41+(0.1*TIME)
so,how to write the condition "time =0 until time=8 " ?
Thanks for advance..
[ASK] IF then else multiple condition
-
- Junior Member
- Posts: 13
- Joined: Tue May 21, 2013 4:06 am
- Vensim version: PLE
-
- Junior Member
- Posts: 13
- Joined: Tue May 21, 2013 4:06 am
- Vensim version: PLE
Re: [ASK] IF then else multiple condition
I just found the way.
IF THEN ELSE(Time=0:OR:Time=1:OR:Time=2:OR:Time=3:OR:Time=4:OR:Time=5,:OR:Time=6:OR:Time=7:OR:Time=8,1.28,0.41+0.1*Time)
Is there any more efficient way ?
IF THEN ELSE(Time=0:OR:Time=1:OR:Time=2:OR:Time=3:OR:Time=4:OR:Time=5,:OR:Time=6:OR:Time=7:OR:Time=8,1.28,0.41+0.1*Time)
Is there any more efficient way ?
-
- Super Administrator
- Posts: 4590
- Joined: Wed Mar 05, 2003 3:10 am
Re: [ASK] IF then else multiple condition
You could use
I would not hard code the 1.28 or 0.1 into the equation (what do these numbers mean?)
A lookup table might be more suitable. If you describe what you are trying to do, we can advise a little better.
Tony.
Code: Select all
IF THEN ELSE(Time>=0:OR:Time<=8 , 1.28 , 0.41+0.1*Time )
Code: Select all
IF THEN ELSE(Time>=0:OR:Time<=8 , some constant , another constant + a third constant * Time )
Tony.
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
-
- Junior Member
- Posts: 13
- Joined: Tue May 21, 2013 4:06 am
- Vensim version: PLE
Re: [ASK] IF then else multiple condition
Oh, good idea to use < and > stupid me..
Time is in year. 0 means 2000,
The characteristic of the data is explained below:
in 2000 until 2008 the index is always 1.28 .. but since 2009, 2010 ,2011,2012 the index is significantly improved (caused by government's policy) and the best equation to represent is 0.41+(0.1*Time).
By the way, how to create a lookup table in vensim?
thank you very much for your help
Time is in year. 0 means 2000,
The characteristic of the data is explained below:
in 2000 until 2008 the index is always 1.28 .. but since 2009, 2010 ,2011,2012 the index is significantly improved (caused by government's policy) and the best equation to represent is 0.41+(0.1*Time).
By the way, how to create a lookup table in vensim?
thank you very much for your help
-
- Super Administrator
- Posts: 4590
- Joined: Wed Mar 05, 2003 3:10 am
Re: [ASK] IF then else multiple condition
It's all in the help system at
http://www.vensim.com/documentation/ind ... ?usr08.htm
http://www.vensim.com/documentation/ind ... ?usr08.htm
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
-
- Junior Member
- Posts: 13
- Joined: Tue May 21, 2013 4:06 am
- Vensim version: PLE
Re: [ASK] IF then else multiple condition
thank you.
once more question , how to lookup only value at time >=6 and >=11, otherwise RANDOM it?
my simulation time is 0 - 20. I need to lookup only value at time 6-11.
i tried this but the result gives me warning "out of bond " and gives always value 178.9 at Time<=5:OR:Time>=12
once more question , how to lookup only value at time >=6 and >=11, otherwise RANDOM it?
my simulation time is 0 - 20. I need to lookup only value at time 6-11.
i tried this but the result gives me warning "out of bond " and gives always value 178.9 at Time<=5:OR:Time>=12
Code: Select all
type: auxiliarry with lookup
equations: IF THEN ELSE(Time<=5:OR:Time>=12,RANDOM NORMAL( 93,241.2,152.9,52.03,0 ),Time)
initial value : ([(0,0)-(11,300)],(6,152.9),(7,126.3),(8,125.2),(9,93),(10,241.2),(11,178.9) )
-
- Super Administrator
- Posts: 4590
- Joined: Wed Mar 05, 2003 3:10 am
Re: [ASK] IF then else multiple condition
Try and keep things simpler. If you embed things like random samples within IF THEN ELSE statements, it makes it impossible to debug.
First define your lookup
My lookup f ([(0,0)-(11,300)],(6,152.9),(7,126.3),(8,125.2),(9,93),(10,241.2),(11,178.9) )
Now get the value from it
value from lookup = my lookup f ( time )
Now get your random sample
random sample = RANDOM NORMAL( 93,241.2,152.9,52.03,0 )
Now make use of the value
value to use in model = IF THEN ELSE ( Time <= 5 :OR: Time >= 12 ,random sample , value from lookup )
Make sure you add your units in as well.
First define your lookup
My lookup f ([(0,0)-(11,300)],(6,152.9),(7,126.3),(8,125.2),(9,93),(10,241.2),(11,178.9) )
Now get the value from it
value from lookup = my lookup f ( time )
Now get your random sample
random sample = RANDOM NORMAL( 93,241.2,152.9,52.03,0 )
Now make use of the value
value to use in model = IF THEN ELSE ( Time <= 5 :OR: Time >= 12 ,random sample , value from lookup )
Make sure you add your units in as well.
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: [ASK] IF then else multiple condition
You might also take a look at the PULSE, STEP and PULSE TRAIN functions for alternatives to the test input with IF THEN ELSE>
/*
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
*/