How do I compute the Kronecker product in GAMS?
The Kronecker products, see https://en.wikipedia.org/wiki/Kronecker_product can easily computed with the matching operator (see https://www.gams.com/latest/docs/UG_SetDefinition.html?search=matching). See details in the following example:
$onText
Kronecker product of two matrices A and B
A is of dimension (m x n)
B is of dimension (p x q)
$offText
sets
m /m1*m3/
n /n1*n2/
p /p1*p4/
q /q1*q3/
;
$eval D1 card(m)*card(p)
$eval D2 card(n)*card(q)
sets
i /i1*i%D1%/
j /j1*j%D2%/
* the matching operator does the magic here
imp(i,m,p) / #i:(#m.#p) /
jnq(j,n,q) / #j:(#n.#q) /
;
* have a look at the sets
display imp, jnq;
table A(m,n)
n1 n2
m1 4 2
m2 1 3
m3 6 5
;
table B(p,q)
q1 q2 q3
p1 7 6 9
p2 8 7 7
p3 4 1 6
p4 5 5 2
;
parameter Kroenecker(i,j);
Kroenecker(i,j) = sum{(imp(i,m,p),jnq(j,n,q)), A(m,n)*B(p,q)};
option decimals=0; display A,B,Kroenecker;