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

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/4pi*K)*log((((((x-xw)2)+(y2))/(((x+xw)2)+(y2))))))=e=phi_2;

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


Enter code here…


Set i well /1/;
scalars
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;

equations
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/4pi*K)*log((((((x-xw)2)+(y2))/(((x+xw)2)+(y2))))))=e=phi_2;
E3… x=l=xw;
E4… obj=e=x;

model saltwater /all/;
solve saltwater using MINLP maximize obj;

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)

On Sunday, April 10, 2016 at 3:28:35 AM UTC-7, AB wrote:

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/4pi*K)*log((((((x-xw)2)+(y2))/(((x+xw)2)+(y2))))))=e=phi_2;

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


Enter code here…


Set i well /1/;
scalars
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;

equations
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/4pi*K)*log((((((x-xw)2)+(y2))/(((x+xw)2)+(y2))))))=e=phi_2;
E3… x=l=xw;
E4… obj=e=x;

model saltwater /all/;
solve saltwater using MINLP maximize obj;

AB,

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

https://support.gams.com/gams:difference_between_the_-operator_and_the_power_function

-Steve

On Wed, Apr 20, 2016 at 1:48 PM, AB wrote:

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)


On Sunday, April 10, 2016 at 3:28:35 AM UTC-7, AB wrote:

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/4pi*K)*log((((((x-xw)2)+(y2))/(((x+xw)2)+(y2))))))=e=phi_2;

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


Enter code here…


Set i well /1/;
scalars
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;

equations
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/4pi*K)*log((((((x-xw)2)+(y2))/(((x+xw)2)+(y2))))))=e=phi_2;
E3… x=l=xw;
E4… obj=e=x;

model saltwater /all/;
solve saltwater using MINLP maximize obj;