Help with an error message: FUNC DOMAIN: x**y, x<0

Skip to first unread message


Apr 10, 2016, 6:28:35 AM4/10/16
to gamsworld
Hello All,

So i have read other or similar posts about this message and I have read about it online, but I still am not able to make sense of it. I think understand that the error is caused by the fact that taking the sqrt( NEG #) is what is supposed to cause this error, but what i dont understand with my code, is that I have the term squared to correct this. I am a programming newbie so this is probably an easily fixable syntax or input error. Would someone look at my code and tell me what they see?? I have included a picture of the equation i am trying to model.
When I run the code, I receive the following message: FUNC DOMAIN: x**y, x<0. There are no red error messages. Also, Im not exactly sure if I need to sum this for what I am trying to do so If that might be relevant information, there it is.

Also, I am aware that there is information in my code that does not actually get used, I just placed it in there because I am trying to compile everything I think is relevant information. Also, this model is far from being complete, I am just trying to fix one error at a time i guess and slowly build from there.

E2..  sum(i,((q1/K)*x)+(Q/4*pi*K)*log((((((x-xw)**2)+(y**2))/(((x+xw)**2)+(y**2))))))=e=phi_2;

Any information or insight that anyone may offer would be greatly appreciated.
Thank you!!

Enter code here...

Set i well /1/;
    K hydraulic conductivity m_d      /100/
    q1 uniform freshwater discharge   /0.6/
    d mean ocean SWE                  /14/
    Rs saltwater density              /1.025/
    Rf freshwater density             /1.000/
    s saltfreshwater ratio            /1.025/
    xw well distance from coast line  /1000/
    y distance between wells          /0/
    phi_1 saltwater head at tow       /2.5/;

positive variable   phi_2 freshwater head
                    Q     Optimal pumping rate
                    x     saltwater toe length;

free variable       obj   objective variable;

E1 constraint on well pumping equation
E2 Equation for the Freshwater potential
E3 toe constraint
E4 objective fcn for max toe length;

E1..  phi_1=l=phi_2;
E2..  sum(i,((q1/K)*x)+(Q/4*pi*K)*log((((((x-xw)**2)+(y**2))/(((x+xw)**2)+(y**2))))))=e=phi_2;
E3..  x=l=xw;
E4..  obj=e=x;

model saltwater /all/;
solve saltwater using MINLP maximize obj;
* I dont know what execerror does
display Q.l, x.l, obj.l;


Apr 21, 2016, 12:02:48 AM4/21/16
to gamsworld
So just in case anyone else reads this, I resolved this issue bu using the power function. I have no idea why it works but it does. so instead of using (x-xw)**2 and ) (x+xw)**2, i used power ((x-xw),2) and power((x+xw),2)

Steven Dirkse

Apr 21, 2016, 10:03:02 AM4/21/16

This link should give you a good idea why your change works as it does.


You received this message because you are subscribed to the Google Groups "gamsworld" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

Steven Dirkse, Ph.D.
GAMS Development Corp.,  Washington DC
Voice: (202)342-0180     Fax: (202)342-0181
Reply all
Reply to author
0 new messages