How do I compute the Kronecker product in GAMS  FAQ

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
User avatar
bussieck
Moderator
Moderator
Posts: 1038
Joined: 7 years ago

How do I compute the Kronecker product in GAMS  FAQ

Post by bussieck »

How do I compute the Kronecker product in GAMS?
User avatar
bussieck
Moderator
Moderator
Posts: 1038
Joined: 7 years ago

Re: How do I compute the Kronecker product in GAMS

Post by bussieck »

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_Set ... h=matching). See details in the following example:

Code: Select all

$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;
Locked