$ontext
Dear GAMS Users,
Could you please someone help me to do the Kronocker Product in GAMS?
I am mainly suffering in writing codes in GAMS for the Kronecker
product.
I would really appreciate your kind cooperation.
Thanks,
Sincerely yours,
Shyam Basnet
Uppsala, Sweden
$offtext
*
* --- Kronecker product of two matrices A and B
*
* A is of dimensions (m x n)
* B is of dimensions (p x q)
set m /m1*m3/
n /n1*n2/
p /p1*p4/
q /q1*q3/;
table A(m,n) "Matrix defined as parameter"
n1 n2
m1 4 2
m2 1 3
m3 6 5;
table B(p,q) "Matrix defined as parameter"
q1 q2 q3
p1 7 6 9
p2 8 7 7
p3 4 1 6
p4 5 5 2;
* Compute the inverse:
set i(m,p), j(n,q);
i(m,p) = yes;
j(n,q) = yes;
parameter Kronecker(m,p,n,q);
Kronecker(i(m,p),j(n,q)) = A(m,n)*B(p,q);
option Kronecker:0:2:2;
display Kronecker;
$exit
---- 56 PARAMETER Kronecker
n1.q1 n1.q2 n1.q3 n2.q1 n2.q2 n2.q3
m1.p1 28 24 36 14 12 18
m1.p2 32 28 28 16 14 14
m1.p3 16 4 24 8 2 12
m1.p4 20 20 8 10 10 4
m2.p1 7 6 9 21 18 27
m2.p2 8 7 7 24 21 21
m2.p3 4 1 6 12 3 18
m2.p4 5 5 2 15 15 6
m3.p1 42 36 54 35 30 45
m3.p2 48 42 42 40 35 35
m3.p3 24 6 36 20 5 30
m3.p4 30 30 12 25 25 10;
Compare with alterative approach:
---- 85 PARAMETER Kroenecker
j1 j2 j3 j4 j5 j6
i1 28 24 36 14 12 18
i2 32 28 28 16 14 14
i3 16 4 24 8 2 12
i4 20 20 8 10 10 4
i5 7 6 9 21 18 27
i6 8 7 7 24 21 21
i7 4 1 6 12 3 18
i8 5 5 2 15 15 6
i9 42 36 54 35 30 45
i10 48 42 42 40 35 35
i11 24 6 36 20 5 30
i12 30 30 12 25 25 10