GAMSでの累乗

GAMSで累乗(冪乗)(x^{n})を計算する方法。私もルールについてよくわすれるのでメモしておきます。

x**n

これがGAMSにおけるx^{n}の一つの表現方法であるが、これはxが正であるときにしか使えない。xが負である ときに x**n という表現を利用すると、次のようなエラーが出る。

**** Exec Error at line 14: rPower: FUNC DOMAIN: x**y, x < 0

GAMS User Manual では ** というオペレータについて次のように説明されている。

x**n is equivalent to the function call rPower(x,y) and is calculated inside GAMS as exp[n*log(x)]. This operation is not defined if x has a negative value, and an error will result. If the possibility of negative values for x is to be admitted and the exponent is known to be an integer, then a function call, power(x,n), is available.

power(x,n)

x が負の値をとるときには、power(x,n) という命令を利用すればよい。ただし、この場合には、n は整数でなければならない。