basic vensim computation issue

Use this forum to post Vensim related questions.
Post Reply
gt4569a
Junior Member
Posts: 8
Joined: Sun Mar 02, 2014 4:15 pm
Vensim version: DSS

basic vensim computation issue

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

Re: basic vensim computation issue

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

Re: basic vensim computation issue

Post 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.
gt4569a
Junior Member
Posts: 8
Joined: Sun Mar 02, 2014 4:15 pm
Vensim version: DSS

Re: basic vensim computation issue

Post by gt4569a »

Timestep = 1 (seconds), So .01 accrues to the stock every second.

thank you
Buzz
Post Reply