Page 1 of 1

Time Steps and If then else

Posted: Tue Sep 14, 2004 10:46 am
by ABridle
I'm using an 'if then else' statement to convert items of one type to another after a certain time. When I use different time steps, not all the items convert when the time hits 12 (works OK with 1, but not with 0.5 or 0.125).

Can anybody explain why they don't convert or what I'm doing wrong - model is attached.

Thanks,

Andrea

Posted: Tue Sep 14, 2004 11:08 am
by Administrator
I don't quite understand the question here. The model is working exactly as it should, you do the conversion when time >12, so at t=12, the conversion has not been done yet.

If you want the conversion to happen at t=12, drop the <= and use < instead.

type1 to type2 =
IF THEN ELSE ( Time < 12 , 0.01 , 1 )

Or have I misunderstood something?

Tony.

Posted: Tue Sep 14, 2004 11:16 am
by ABridle
At time 14, when running with time step 1, all items have converted from type 1 to type 2.

However when running with a smaller time step, there are still type 1 items (when they should have been converted to type 2).

Hope that makes sense.

Posted: Tue Sep 14, 2004 11:41 am
by Administrator
I understand.

have a look at
http://www.vensim.com/documentation/html/23395.htm

This explains Euler integration.
LEVELTime+TIME STEP = LEVELTime + TIME STEP * RATETime

As you have a time step of 1, everything is happening as you expect it to. Your "Conversion" parameter is not a rate (not time dependant), so when the time step changes, the calculation in the level changes as well.

Change your "conversion" parameter to be a rate, eg
conversion[TYPE1] = ( TYPE 2 TO TYPE 1 * Number[TYPE2] - type1 to type2 * Number[TYPE1] ) / TIME STEP

and that should have the desired effect.

I would also suggest putting units in for your parameters, a units check would have told you that "conversion" needed to be dmnl/month and not dmnl.

Hope this makes sense.

Tony.

Posted: Thu Sep 16, 2004 11:13 am
by ABridle
Is there any way of having the change from type 1 to type 2 as a constant per month?

When I put the units as dmsl/month (and change the units of conversion), I get the problem that not all the items convert from one type to the other at the specified time for different time steps.

(Model adjusted and attached)

Posted: Mon Sep 20, 2004 7:42 am
by Pruyn
If you want to instantly change the amount, make sure you divede this by time step. This way it will all be done during one time step and not one time period (e.g. month or day). See also Tony's comment.
I changed the if then else construction a bit so it will work. The first part is time step independent, the second part isn't. See adjusted mdl.

Jeroen