Hello I need to sum the elements of the two main diagonal elements of a 9x9 matrix. The first one is easy Sum(i,x(i,i)) but for the second I tried sum(i,x(i,9-i)) or analogous variations but I didn't succeed.
Thanks for your help
Problems with syntax of GAMS
3 posts • Page 1 of 1
With lag and leads (see https://www.gams.com/latest/docs/UG_Ord ... dOperators ) you need to have i+(expr) or i-(expr) (-- or ++) also work. So your 9-i is equivalent to i-i+9-i = i+(9-2*i). Here is the complete GAMS program:
Code: Select all
set i /1*9/; alias (i,j); parameter x(i,j); x(i,j) = uniformInt(0,10); scalar diag1, diag2; diag1 = sum(i, x(i,i)); diag2 = sum(i, x(i,i+(card(i)-2*ord(i)))); option x:0:1:1; display x, diag1, diag2;