You are here

non-negativity of variables

I am struggling with clamping a 'compartment' so that it does not become negative. Trying to control this with 'if' statements on the outflow does not help. Probably because we really don't know which is the current value and comparing the current size of a compartment with the outflow does not do the trick. In the dialogue box where we set the initial condition for the compartment, the min and max boxes are actually active, so the assumption was that we can clamp it here. No luck: the value still goes negative.

It does seem to work if I use output = min(compartment, output)

Any other way to do it?

Forums: 
Taxonomy upgrade extras: 

Yes, thanks, I forgot to divide by dt. This helps.

So what is the purpose on the min and max boxes in the compartment dialogue box? They don't seem to perform as you would expect.

Min and max boxes in the compartment dialogue box, as in general to the equation dialog box for all variables, are there for "variable parameters". Parameters that the user ran change durnig a run. The min and max values provide limits for the "slider" user interface elements that the user can move to change the value.