Division by zero error

559 views
Skip to first unread message

Mohd Shuaib

unread,
Jul 2, 2012, 2:12:08 PM7/2/12
to gams...@googlegroups.com
Hi All,
I encountered a division by zero error when i tried to run my model.
Specifically, the error takes me to the following lines in my gams code:
 
tyh(H)         = DTHO(H)/YHO(H);   (**** Exec Error at line 28078: division by zero (0))
psi(H)         = SHO(H)/YDHO(H);  (**** Exec Error at line 28138: division by zero (0))
 
I have also defined them under variable assignment as follows:
YHO(H)         = lambda_w(H)+lambda_r(H)+TGO(H)+TRHO(H);
SHO(H)         = YHO(H)-DTHO(H)-SUM(TR,CO(H,TR));
 
Can someone please assist towards rectifying this errors.
 
Thank you in advance.

herve guene

unread,
Jul 2, 2012, 4:40:00 PM7/2/12
to gams...@googlegroups.com
check the values of your parameters,
specially those that are denominators, because the default value of a parameter is zero. so untill you give or compute an initial value for them you'll get division by zero error.
 
Merci et bonne réception!
- - - - - - -- -- -- --- --- --- ----- ---- ---- ---- ----
M.  Hervé Jean-Louis GUENE
Ingénieur Statisticien - Economiste
Institut National de la Statistique et de la Démographie/ Burkina-Faso
cel:(+226) 71 31 53 52/ 75 503 803/ 78 35 77 76

 

De : Mohd Shuaib <mohammedi...@gmail.com>
À : gams...@googlegroups.com
Envoyé le : Lundi 2 juillet 2012 18h12
Objet : Division by zero error

--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To post to this group, send email to gams...@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


Dileep Damayyawar

unread,
Jul 3, 2012, 2:01:27 AM7/3/12
to gams...@googlegroups.com
Shuaib,

The parameter in denominator having some zeros. So that this error is occurring.

Prepare one set of H whose YHO is more than 0, then use that set with $

Ex- positive_H
tyh(H) =e= DTHO(H)/(YHO(H)$ positive_H);

Do it same for other equation.

Regards
Dileep Damayyawar

 


--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To post to this group, send email to gams...@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.



--

        


Mohammed Shuaibu

unread,
Jul 3, 2012, 2:02:31 PM7/3/12
to gams...@googlegroups.com
Thanks a lot Dileep!
Mohammed I. Shuaibu
PhD Candidate, Department of Economics & Research Fellow, Trade Policy Research and Training Programme (TPRTP)
University of Ibadan
P: +2348033147465

"Above every possessor of knowledge there is One"
Sent from my BlackBerry wireless device from MTN

From: Dileep Damayyawar <dilipda...@gmail.com>
Date: Tue, 3 Jul 2012 11:31:27 +0530
Subject: Re: Division by zero error

Mohammed Shuaibu

unread,
Jul 3, 2012, 2:02:11 PM7/3/12
to gams...@googlegroups.com
Thanks a lot Herve Guene.
Mohammed I. Shuaibu
PhD Candidate, Department of Economics & Research Fellow, Trade Policy Research and Training Programme (TPRTP)
University of Ibadan
P: +2348033147465

"Above every possessor of knowledge there is One"
Sent from my BlackBerry wireless device from MTN

From: herve guene <hgu...@yahoo.fr>
Date: Mon, 2 Jul 2012 21:40:00 +0100 (BST)
Subject: Re: Division by zero error

Renger van Nieuwkoop

unread,
Jul 3, 2012, 4:28:21 PM7/3/12
to gams...@googlegroups.com

Hi Jackson

It looks like one of the c(i)  is zero…

Just display them and see if one of them is zero (be sure to add eps to the values, so Gams reports the zero values (  e.g. c(i) = c(i) + EPS)

Renger

 

From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of Jackson
Sent: Tuesday, July 03, 2012 10:22 PM
To: gams...@googlegroups.com
Cc: herve guene
Subject: Re: Division by zero error

 

Hello Mr. Herve, 

 

I'm also having a similar error.  This is my objective function code:

 

Objfunction  ..      z =e= sum((i), (  x(i)*((m(i)/c(i)))  ) )

 

The x(i) is my variable.

The m(i) and c(i) are both parameters.

 

However, I've already read in data from excel for each parameter.  Would this still cause the c(i) to be zero?  How can I fix this?

 

Thanks,

Jackson

To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/90W3M2OxjzQJ.

Renger van Nieuwkoop

unread,
Jul 4, 2012, 5:09:44 AM7/4/12
to gams...@googlegroups.com

HI Jackson

 

Assume you have a set I /i1, i2,i3/ and a parameter c(i) that is initialized as follows:

 

c(“i1”) = 2;

c(“i2”) = 0;

c(“i3”) = 3;

 

If you do a display, gams will display this as follows:

 

----      9 PARAMETER c 

 

i1 2.000,    i3 3.000

 

The value for i2 is not reported. Here it is easy to spot this missing value, as you only have 3 set elements, but if you have lots of I’s it gets harder to spot the zeros.

 

If you do the following

c(i) = c(i) + EPS;

 

Gams adds a very, very small figure to c(i), which does not impact the results. Your output will now be:

 

i1 2.000,    i2   EPS,    i3 3.000

 

and you see the “zero” easily.

 

Another way would be:

 

Parameter testforzeros(i);

 

Testforzeros(i)$(c(i) eq 0) = 1;

Display testforzeros;

 

With the following output (even if you added EPS!)

 

----     16 PARAMETER testforzeros 

 

i2 1.000

 

Hope, this helps. If you still have this error message, send the model and I have a look at it.

 

Cheers

Renger

 

 

From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of Jackson
Sent: Tuesday, July 03, 2012 10:42 PM
To: gams...@googlegroups.com
Subject: Re: Division by zero error

 

Hi Renger,

 

Thanks for helping me out today.

 

I ran the display for parameter c(i) and none of the values are zero.  Where do I add the eps to values?  Under parameters or equations?

 

Thanks,

Jackson

To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/8JwCjqGicmYJ.

Partha Das

unread,
Nov 5, 2015, 8:30:27 AM11/5/15
to gamsworld
I am trying to calculate a parameter x=y/(y^2+z^2).
I have written   x=y/(sqr(y)+sqr(z))

the values of y & z parameters are already defined. y contains some zeros, but z contains no zeros. still I am getting UNDF as the output (i.e. x). Any help?

Partha Das

unread,
Nov 6, 2015, 3:09:07 AM11/6/15
to gamsworld
Actually I have the following issue: 
I am calculating p(z) from the table as follows with no error, 
set z /b1*b6/  ;
table t(z,*)   dat

         r              x
b1     0.005     0.17
b2     0.001     0.037
b3     0.003     0.258
b4     0.007     0.197
b5     0.001     0.037
b6     0.002     0.14 ;

parameter p(z);
p(z)=t(z,'r')/(sqr(t(z,'r'))+sqr(t(z,'x')));

but when we define the table like the following I have division by  zero error
set z /b1*b6/  ;
table t(z,z,*)   dat

                   r        x
b1.b2     0.005     0.17
b2.b3     0.001     0.037
b1.b4     0.003     0.258
b2.b4     0.007     0.197
b4.b5     0.001     0.037
b5.b6     0.002     0.14
b3.b6     0.001     0.018 ;

parameter p(z,z);
p(z,z)=t(z,z,'r')/(sqr(t(z,z,'r'))+sqr(t(z,z,'x')));

Any clue?

Renger van Nieuwkoop

unread,
Nov 6, 2015, 3:38:10 AM11/6/15
to gams...@googlegroups.com

Hi Partha

 

Two remarks:

-          In your second calculation you will have zeros for alle combinations of the set z and itself that are not available in the table (e.g. b1.b1) which causes the error. You just add a $-condition on the left hand side to get rid of the errors.

-          In your second calculation of t you only calculate the diagonal elements (b1.b1, b2.b2, etc.). If you want to calculate all the elements, you should define an alias for z.

 

Here is the way it works for me:

 

alias(z,z1);

parameter p(z,z);

p(z,z1)$(sqr(t(z,z1,'r'))+sqr(t(z,z1,'x')))=t(z,z1,'r')/(sqr(t(z,z1,'r'))+sqr(t(z,z1,'x')));

 

Chees

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.


To post to this group, send email to gams...@googlegroups.com.

Partha Das

unread,
Nov 6, 2015, 4:29:25 AM11/6/15
to gamsworld
It is a great help Renger. Thank you so much.
...
Reply all
Reply to author
Forward
0 new messages