You are here

removing a proportion of compX at time(x)

Hey there,

im having a problem removing a proportion of compartment X via the outflow at time X

for example i have 100 in compartment X at time 100. I have been using the formula

if age (which is time(1)-init_time(1)) ==100 then 0.08*compX else 0

this is not working to take 8% of the compartment out via the flow and nothing else. i think it is taking nothing out.

So i tried to use the formula

if age>100 and age

this takes out too much.

What is the solution, seeing that removing it from the compartment via the outflow is what i want.

Ls

Forums: 

dont worry i overcame my stupidity by

if age>100 and age

and this takes out 8%

cheers

LS

Yes, there is the problem of comparing floating point numbers for equality when any tiny rounding error will make the computed values not exactly the same so checking for a range of values is neccessary.

If your code works I think you must be using a timestep (dt) of 1. In general you must include the dt in your expression to calculate the desired outflow. I've taken the below from the help file.

Quote:
For example, consider a model with a time unit of year, a time step of 0.1, and with a compartment X from which we want to remove 5 units at the instant that some condition, which only lasts for 1 time step (0.1 years), is met. If we simply had a flow out that was zero when the condition was not met, and was 5 when the condition was met, then for one time step the flow would be 5 (units per year): hence, only 0.5 units would be removed in the 1/10th of a year, not the 5 we intended. What we need to do is to artificially inflate the flow rate by a factor of 10 (in this case, with a time step of 0.1) for this one time step. We do this by dividing the flow rate (in our flow equation) by 0.1 (in this case), or by dt(1) in general. The flow rate then appears to be 50 units per year for that one time step, giving a loss of 5 units in the one time step.

For the help on dt see http://simulistics.com/help/equations/functions/dt.htm or the help in Simile.

A more general expression checking for the event time as well as calculating the desired outflow is (courtesy of Jasper):
if time()>=EventTime-dt()/2 and time() else 0

Jonathan