1

In GAMS, I need to put an equation in a function. Look at this example

$ontext
minimize 5x^2+3x-12
subject to
4x+2x^2<10
$offtext

variable OF, x;
equation obj,cons;
obj .. OF=E=5*x*x+3*x-12;
cons .. 4*x+2*x*x=L=10;
model this /all/;
solve this using NLP maximizing OF;
display x.l,OF.l,cons.l;

The solution is

VARIABLE x.L                   =        1.449  
VARIABLE OF.L                  =        2.854  
EQUATION cons.L                =       10.000

Now, let say I want to define the objective as a function:

f(x)=5x^2+3x-12

and replace the first constraint with

obj .. OF=E=f(x);

How should I do this?

Thank you!

1 Answers1

2

I am not sure, if I understand your motivation to do this, but what you could do, is using a macro like this:

variable OF, x;
equation obj,cons;

$macro f(x) 5*x*x+3*x-12

obj .. OF=E=f(x);
cons .. 4*x+2*x*x=L=10;
model this /all/;
solve this using NLP maximizing OF;
display x.l,OF.l,cons.l;
Lutz
  • 2,197
  • 1
  • 10
  • 12