[ASK] IF then else multiple condition

Use this forum to post Vensim related questions.
Post Reply
diajeng permata
Junior Member
Posts: 13
Joined: Tue May 21, 2013 4:06 am
Vensim version: PLE

[ASK] IF then else multiple condition

Post 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..
diajeng permata
Junior Member
Posts: 13
Joined: Tue May 21, 2013 4:06 am
Vensim version: PLE

Re: [ASK] IF then else multiple condition

Post 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 ?
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: [ASK] IF then else multiple condition

Post 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.
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
diajeng permata
Junior Member
Posts: 13
Joined: Tue May 21, 2013 4:06 am
Vensim version: PLE

Re: [ASK] IF then else multiple condition

Post by diajeng permata »

Oh, good idea to use < and > :D stupid me.. :D

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
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: [ASK] IF then else multiple condition

Post by Administrator »

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
diajeng permata
Junior Member
Posts: 13
Joined: Tue May 21, 2013 4:06 am
Vensim version: PLE

Re: [ASK] IF then else multiple condition

Post 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) )
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: [ASK] IF then else multiple condition

Post 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.
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: 3811
Joined: Wed May 24, 2006 4:54 am

Re: [ASK] IF then else multiple condition

Post 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>
Post Reply