2

When coding in GAMS and defining my EQUATIONS, I sometimes need to reuse a certain function of the variables. How do I define this function so that I can reuse it, as opposed to having to constantly write it out in my equation definitions?

merija
  • 215
  • 1
  • 4

1 Answers1

1

You can use a macro to do this. The syntax is documented here: https://www.gams.com/latest/docs/UG_DollarControlOptions.html#UG_DollarControl_MacrosInGAMS

You could for example define a function 'sqrtsqr'

$macro sqrtsqr(x) sqrt(x*x)

And use it in your equations

my_equation.. sqrtsqr(x) =E= y;
Martin Bonde
  • 536
  • 3
  • 11