User Tools

Site Tools


gams:difference_between_the_-operator_and_the_power_function

This is an old revision of the document!


What is the difference between the ** operator and the power function?

The power function power(x) (or sqr(x) is an integer power and thus the exponent must be an integer.

This is not required for the ** operator. x**2 is a a real power and gets evaluated as exp(2*log(x)). However, with the ** operator the exponent must be a positive number to avoid an compilation error. So:

scalar test; 
test = (-3)**4; 
* note: this is not the same as -3**4,which will be treated as -(3**4) 
display test; 

will give you an error:

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

This formulation will work:

scalar test; 
test = power(-3,4); 
display test; 
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/difference_between_the_-operator_and_the_power_function.1207055932.txt.gz · Last modified: 2008/04/01 15:18 by support