2

I'm trying to initialize a matrix in an OPL script (an execute{}block) Each element must be set to a float power (> 0)

The pow function is not recognized in script, so I tried the ^ operator... but it is not what I expected : the reference says "^ means power in OPL and bitwise xor in Script"

So for now I just used a for() loop, which works but does not accept floating powers :

var temp;
for (var p = 1; p<=nbP; p++){
   for (var n = 1; n <= nbC; n++){
       temp = w[n][p] / i[p];
       MATRIX[n][p] = 1;
       for (var i = 1; i <= desiredPower; i++){
          MATRIX[n][p] = tempNGSI * MATRIX[n][p];
       }   
   }           
}

Is there an equivalent for pow() in OPL script? How can I do otherwise? Note that for() blocks are not recognized outside of the script blocks (execute{})

David Nehme
  • 21,379
  • 8
  • 78
  • 117
Aname
  • 515
  • 4
  • 16
  • Why are you using for loops to initialize the matrix? The OPL language itself has declarative ways to initialize matrices. – David Nehme Jul 17 '14 at 16:26
  • @DavidNehme I wanted to make this calculation inside the OPL .mod so my data files needs no change, that's why... I guess I will have to make a specific input file for this one – Aname Jul 17 '14 at 16:30

1 Answers1

2

OPL script (like it's cousin javascript) has the basic mathematical functions wrapped up in the Math object.

for (var p = 1; p<=nbP; p++){
   for (var n = 1; n <= nbC; n++){
       MATRIX[n][p] = Math.pow(w[n][p] / i[p], desiredPower);
   }           
}
David Nehme
  • 21,379
  • 8
  • 78
  • 117