Page 1 of 1

basic vensim computation issue

Posted: Tue Nov 11, 2014 11:00 pm
by gt4569a
Hello all,

In searching I saw some topics that touched on this question, but haven't seen anyone address what I would consider to be the more basic issue: why is it possible, when the inflow to a stock is a (constant) rational number that is a fraction of 1, that the stock value can sometimes never equal 1?

For example-

inflow = 1/100

stock = inflow - outflow

outflow = IF THEN ELSE(stock = 1, stock, 0)

The outflow returns a value of 0 forever. It never pulls the value of "stock". To correct this issue I usually "cheat" and modify the outflow equation to read IF THEN ELSE(stock +.001 >= 1, stock, 0). I can understand why I may have to do this if the inflow were an irrational number... but it seems to me that cumulating 0.01 for 100 timesteps should result in a solid 1.00000000000000 ad inf.

Apologies if this has been discussed elsewhere, I may not have searched on the correct keyword. I am using DSS v6.1c if that info is relevant. Thank you -Buzz

Re: basic vensim computation issue

Posted: Wed Nov 12, 2014 8:27 am
by Administrator
What time step are you using in your model? And what is the value of the stock?

It may well be that there are rounding issues. Usually when emptying a stock, I'll use something like

Code: Select all

outflow = IF THEN ELSE(stock >= 1, stock / time step , 0 )

Re: basic vensim computation issue

Posted: Wed Nov 12, 2014 10:22 pm
by tomfid
I think the short answer is that 1/100 isn't precisely .01 in binary - it's 0.01000000000000000020816681711722. If you multiply 100*(1/100) the error is reversible, but if you sum 1/100 a hundred times, the error accumulates.

Re: basic vensim computation issue

Posted: Thu Nov 13, 2014 7:14 pm
by gt4569a
Timestep = 1 (seconds), So .01 accrues to the stock every second.

thank you
Buzz