divided by zero Topic is solved

Problems with syntax of GAMS
Post Reply
douglaskuo
User
User
Posts: 21
Joined: 3 years ago

divided by zero

Post by douglaskuo »

Dear all, (or Atharv),
I amended one title "secrub" to "comrub". No duplicate problem anymore.
I encounter the problem "divided by zero" in line 46.
I check the entry: sam('total',j) and sam(i,'total') and am sure they are not zero (by display **,*)
I appreciate it if some one can help me.
Thanks and regards,
Douglas

*Base on the traget value of column J to adjust SAM (R adjustment)
sam('total',j)=sum(i,sam(i,j));
sam(i,j)=(sam(i,j)/sam('total',j))*sam('tartot',j);

* *Base on the traget value of column J to adjust SAM (S adjustment)
sam(i,'total')=sum(j,sam(i,j)) ;
sam(i,j)=(sam(i,j)/sam(i,'total'))*sam(i,'tartot');

HSRTWN2020.gms
(2.3 KiB) Downloaded 183 times
samjuly20201019.xlsx
(29.8 KiB) Downloaded 189 times
douglaskuo
User
User
Posts: 21
Joined: 3 years ago

Re: divided by zero

Post by douglaskuo »

Should be:
*** Error at line 46: division by zero (0)
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: divided by zero

Post by abhosekar »

I think this is because of the column 'secede' which is in your set i, but it is not in the initial definition of the parameter sam.
When GAMS executes line 46 for the first time, it does not have any value for sam('total', 'secede') which is why you get first division by zero error as it is undefined.
After this operation, gams adds a column for 'secede' with all undefined values.
When you add columns, the undefined numbers get propagated which results in even more errors.

As you rightly observed, the initial value of sam('total', j) parameter is not zero. However, as your code carries out the iterations, within 2 iterations, it becomes undefined.
To observe this, change your while loop to
while (iter <2, ...
instead of while(iter < 1000 and maxdis > 1e-10,..

just before and after line 46, add a line
display sam;

Actual solution to this question depends on what you would like to do with the column 'secede'.

Hope this helps.

- Atharv
douglaskuo
User
User
Posts: 21
Joined: 3 years ago

Re: divided by zero

Post by douglaskuo »

Great thanks. I want to run RAS adjustment. I got the results. Thanks.
Post Reply