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

Archive of Gamsworld Google Group
Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 1 year ago


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/;
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/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
execerror=0;
display Q.l, x.l, obj.l;









--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 1 year ago


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/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/;
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/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
execerror=0;
display Q.l, x.l, obj.l;









--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Archiver
User
User
Posts: 7876
Joined: 1 year ago

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

Postby Archiver » 1 year ago

AB,

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

https://support.gams.com/gams:differenc ... r_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/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/;
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/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
execerror=0;
display Q.l, x.l, obj.l;









--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.




--
Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdirkse@gams.com
http://www.gams.com


Who is online

Users browsing this forum: No registered users and 2 guests