Page 1 of 1

how to write the quadratic and logarithmic model in GAMS

Posted: Fri Sep 09, 2022 8:00 pm
by ersuhaib786
I am modelling a consumer model, but i don't know how to write this type of equation . Kindly help me out with the equation writing. yours valuable suggestions, comments and help are welcomed. I am attaching the .gms file (code) and JPG file (equations) for the reference. Kindly help me out.
Equations
Equations

Re: how to write the quadratic and logarithmic model in GAMS

Posted: Sat Sep 10, 2022 8:37 am
by bussieck
You have functions U1/2/3(x) that have two different algebra parts for different argument ranges.You are already in the NLP domain (because of log) so you can just use the GAMS function ifthen (https://www.gams.com/latest/docs/UG_Par ... _22_ifThen) to model this. For example, U2(x) = ifthen(x>0, beta*log(omega*x+1), 0). Please note that GAMS evaluates all three parts of the ifthen function independent of the condition in the first argument. That means, if you write it like I just did you will get function evaluation errors with x<-1/omega because then GAMS tries to apply the log function to a negative number. You can avoid this and don't change the overall outcome of the expression by e.g. writing U1 as ifthen(x>0, beta*log(omega*abs(x)+1), 0).

Hope this helps,
-Michael

Re: how to write the quadratic and logarithmic model in GAMS

Posted: Sun Sep 11, 2022 2:02 pm
by ersuhaib786
Thank you so much for the reply. I can now evaluate U2,U3, but I am getting error for writing U.1 would u kindly review it. I am attaching .gms file for the review, also there are two parts of U1 with 3 bounds. Kindly help me out.
Customer profit maximization.gdx
(2.11 KiB) Downloaded 89 times

Re: how to write the quadratic and logarithmic model in GAMS

Posted: Thu Sep 15, 2022 8:22 am
by bussieck
You sent a GDX file. Nothing I can do with this. -Michael

Re: how to write the quadratic and logarithmic model in GAMS

Posted: Thu Sep 15, 2022 11:36 am
by ersuhaib786
My mistake, unfortunately I uploaded the .gdx file. I have attached now the .gms file and my problem formulation (JPG file) for the reference. Kindly review it and where do I have to write this gaama (sqr(omega)/2*alpha) part.- Line 200
cus model.jpeg

Re: how to write the quadratic and logarithmic model in GAMS

Posted: Fri Sep 16, 2022 12:58 pm
by bussieck
GAMS requires operators between all parts of the expression. In papers for multiplication the '*' sign is often left out. You need that in GAMS (and many other languages):

Code: Select all

parameter U1;
U1(t)= ifthen(Q1(t)<=omega/alpha, gaama*(omega*Q1(t) -alpha/2*sqr(Q1(t))), omega/alpha);
-Michael

Re: how to write the quadratic and logarithmic model in GAMS

Posted: Fri Sep 16, 2022 1:21 pm
by ersuhaib786
In Equation 2, there are four terms. where to write [gaama*(omeega**2)/(2*alpha)] ... where do i have to write this term in my code.

Re: how to write the quadratic and logarithmic model in GAMS

Posted: Sat Sep 17, 2022 11:41 am
by bussieck
I don't understand the question. -Michael

Re: how to write the quadratic and logarithmic model in GAMS

Posted: Sat Sep 17, 2022 1:50 pm
by ersuhaib786
where to write the encircled part of the equation in the code. i have attached the JPG file.

Re: how to write the quadratic and logarithmic model in GAMS

Posted: Sun Sep 18, 2022 9:12 am
by bussieck
In the "else" or false_expression part of the function: ifthen(expression, true_expression, false_expression). -Michael