how to write the quadratic and logarithmic model in GAMS

 User
 Posts: 10
 Joined: 2 years ago
how to write the quadratic and logarithmic model in GAMS
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.
Last edited by ersuhaib786 8 months ago, edited 1 time in total.
Re: how to write the quadratic and logarithmic model in GAMS
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
Hope this helps,
Michael

 User
 Posts: 10
 Joined: 2 years ago
Re: how to write the quadratic and logarithmic model in GAMS
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.
Re: how to write the quadratic and logarithmic model in GAMS
You sent a GDX file. Nothing I can do with this. Michael

 User
 Posts: 10
 Joined: 2 years ago
Re: how to write the quadratic and logarithmic model in GAMS
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
Last edited by ersuhaib786 8 months ago, edited 1 time in total.
Re: how to write the quadratic and logarithmic model in GAMS
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):
Michael
Code: Select all
parameter U1;
U1(t)= ifthen(Q1(t)<=omega/alpha, gaama*(omega*Q1(t) alpha/2*sqr(Q1(t))), omega/alpha);

 User
 Posts: 10
 Joined: 2 years ago
Re: how to write the quadratic and logarithmic model in GAMS
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
I don't understand the question. Michael

 User
 Posts: 10
 Joined: 2 years ago
Re: how to write the quadratic and logarithmic model in GAMS
where to write the encircled part of the equation in the code. i have attached the JPG file.
Last edited by ersuhaib786 8 months ago, edited 2 times in total.
Re: how to write the quadratic and logarithmic model in GAMS
In the "else" or false_expression part of the function: ifthen(expression, true_expression, false_expression). Michael