Page 1 of 1
[ASK] IF then else multiple condition
Posted: Sat Jun 15, 2013 9:11 am
by diajeng permata
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..
Re: [ASK] IF then else multiple condition
Posted: Sat Jun 15, 2013 11:28 am
by diajeng permata
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 ?
Re: [ASK] IF then else multiple condition
Posted: Sat Jun 15, 2013 11:55 am
by Administrator
You could use
Code: Select all
IF THEN ELSE(Time>=0:OR:Time<=8 , 1.28 , 0.41+0.1*Time )
I would not hard code the 1.28 or 0.1 into the equation (what do these numbers mean?)
Code: Select all
IF THEN ELSE(Time>=0:OR:Time<=8 , some constant , another constant + a third constant * Time )
A lookup table might be more suitable. If you describe what you are trying to do, we can advise a little better.
Tony.
Re: [ASK] IF then else multiple condition
Posted: Sat Jun 15, 2013 1:17 pm
by diajeng permata
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
Re: [ASK] IF then else multiple condition
Posted: Sun Jun 16, 2013 5:54 pm
by Administrator
Re: [ASK] IF then else multiple condition
Posted: Sun Jun 16, 2013 11:50 pm
by diajeng permata
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
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) )
Re: [ASK] IF then else multiple condition
Posted: Mon Jun 17, 2013 7:56 am
by Administrator
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.
Re: [ASK] IF then else multiple condition
Posted: Mon Jun 17, 2013 12:42 pm
by tomfid
You might also take a look at the PULSE, STEP and PULSE TRAIN functions for alternatives to the test input with IF THEN ELSE>