how to write the quadratic and logarithmic model in GAMS

Problems with modeling
Post Reply
ersuhaib786
User
User
Posts: 10
Joined: 3 years ago

how to write the quadratic and logarithmic model in GAMS

Post 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
Last edited by ersuhaib786 1 year ago, edited 1 time in total.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

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

Post 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
ersuhaib786
User
User
Posts: 10
Joined: 3 years ago

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

Post 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 84 times
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

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

Post by bussieck »

You sent a GDX file. Nothing I can do with this. -Michael
ersuhaib786
User
User
Posts: 10
Joined: 3 years ago

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

Post 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
Last edited by ersuhaib786 1 year ago, edited 1 time in total.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

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

Post 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
ersuhaib786
User
User
Posts: 10
Joined: 3 years ago

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

Post 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.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

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

Post by bussieck »

I don't understand the question. -Michael
ersuhaib786
User
User
Posts: 10
Joined: 3 years ago

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

Post by ersuhaib786 »

where to write the encircled part of the equation in the code. i have attached the JPG file.
Last edited by ersuhaib786 1 year ago, edited 2 times in total.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

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

Post by bussieck »

In the "else" or false_expression part of the function: ifthen(expression, true_expression, false_expression). -Michael
Post Reply