Post Reply 
Kronecker Product?
02-17-2019, 02:39 PM
Post: #1
Kronecker Product?
How could a Kronecker Product be found with the hp prime?
(This would be like Matlab's kron() command, or Wolfram's KroneckerProduct() command).

https://en.wikipedia.org/wiki/Kronecker_product

I'm no expert on this subject matter, but have recently encountered a need for this in connection with an energy flow problem. Here is an example of a 4x4 identity matrix, with a 2x2 matrix, resulting in an 8x8 Kronecker product:

Example (using wxmaxima here):

(%i3) a:ident(4);
b:matrix ([1,-1],[-1,1]);
kronecker_product(a,b);

(a) matrix(
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]
)
(b) matrix(
[1, -1],
[-1, 1]
)
0 errors, 0 warnings

(%o3) matrix(
[1, -1, 0, 0, 0, 0, 0, 0],
[-1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, -1, 0, 0, 0, 0],
[0, 0, -1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, -1, 0, 0],
[0, 0, 0, 0, -1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 1, -1],
[0, 0, 0, 0, 0, 0, -1, 1]
)
Find all posts by this user
Quote this message in a reply
02-17-2019, 03:47 PM (This post was last modified: 02-17-2019 04:25 PM by informach.)
Post: #2
RE: Kronecker Product?
Hi!, DrD :
You can use, for calculate matrices, with Hadamard, as …
Syntax :
Hadamard bound of a sub-matrix or element by element multiplication of 2 matrices. hadamard(Matrix,[Matrix]) Examples: hadamard([[1,2],[3,4]]) returns 5√5 hadamard([[1,2],[3,4]],[[3,4],[5,6]]) returns [[3,8],[15,24]]
From … User_Guide_EN_2018_01_12_1.pdf (page 475).
Too, you can see, from Namir Shammas http://h20331.www2.hp.com/hpsub/download...ionsv3.pdf
Find all posts by this user
Quote this message in a reply
02-17-2019, 05:48 PM
Post: #3
RE: Kronecker Product?
(02-17-2019 03:47 PM)informach Wrote:  Hi!, DrD :
You can use, for calculate matrices, with Hadamard, as …
Syntax :
Hadamard bound of a sub-matrix or element by element multiplication of 2 matrices. hadamard(Matrix,[Matrix]) Examples: hadamard([[1,2],[3,4]]) returns 5√5 hadamard([[1,2],[3,4]],[[3,4],[5,6]]) returns [[3,8],[15,24]]
From … User_Guide_EN_2018_01_12_1.pdf (page 475).
Too, you can see, from Namir Shammas http://h20331.www2.hp.com/hpsub/download...ionsv3.pdf

The hadamard() command fails. Please note that the matricies in the example I provided are of differing sizes: a(4x4) and b(2x2), and produce an 8x8 Kronecker product.

I'm not seeing any in-built commands that produce the Kronecker product. It may have to be created as an external command, or function.

[attachment=6953]
Find all posts by this user
Quote this message in a reply
02-17-2019, 07:52 PM (This post was last modified: 02-17-2019 08:01 PM by Didier Lachieze.)
Post: #4
RE: Kronecker Product?
Here is a CAS program to calculate the Kronecker product of two matrices:

Code:
#cas
kronecker(a,b):=
BEGIN
 local m,n,p,q;
 m:=rowDim(a); n:=colDim(a);
 p:=rowDim(b); q:=colDim(b);
 makemat((j,k)→a(iquo(j-1,p)+1,iquo(k-1,q)+1)*b(((j-1) MOD p)+1,((k-1) MOD q)+1),m*p,n*q);
END;
#end
Find all posts by this user
Quote this message in a reply
02-17-2019, 08:06 PM
Post: #5
RE: Kronecker Product?
(02-17-2019 07:52 PM)Didier Lachieze Wrote:  Here is a CAS program to calculate the Kronecker product of two matrices:

Code:
#cas
kronecker(a,b):=
BEGIN
 local m,n,p,q;
 m:=rowDim(a); n:=colDim(a);
 p:=rowDim(b); q:=colDim(b);
 makemat((j,k)→a(iquo(j-1,p)+1,iquo(k-1,q)+1)*b(((j-1) MOD p)+1,((k-1) MOD q)+1),m*p,n*q);
END;
#end

Thank you, kind sir! Excellent, as always. I was a bit surprised not to find this in the suite of similar commands, but I'll add this into my collection!
Find all posts by this user
Quote this message in a reply
02-18-2019, 08:58 AM
Post: #6
RE: Kronecker Product?
Here is a slightly updated version, replacing the Home MOD function by the CAS irem function to be more consistent:

Code:
#cas
kronecker(a,b):=
BEGIN
 local m,n,p,q;
 m:=rowDim(a); n:=colDim(a);
 p:=rowDim(b); q:=colDim(b);
 makemat((j,k)→a(iquo(j-1,p)+1,iquo(k-1,q)+1)*b(irem(j-1,p)+1,irem(k-1,q)+1),m*p,n*q);
END;
#end
Find all posts by this user
Quote this message in a reply
02-18-2019, 10:26 AM
Post: #7
RE: Kronecker Product?
Thanks for the update. I was studying your makelist construction, and thinking to myself how nicely crafted, made even better, now, by using only CAS commands.

There is a lot, in just your short program, to be learned about the hp prime, CAS/HOME, and programming; embedded in it. This would make a great example for the user guide, to introduce CAS programming structures, and techniques.

Short, efficient, and to the point! Very well done!

-Dale-
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)