Kronecker Product?
02-17-2019, 02:39 PM
Post: #1
 DrD Senior Member Posts: 1,117 Joined: Feb 2014
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]
)
02-17-2019, 03:47 PM (This post was last modified: 02-17-2019 04:25 PM by informach.)
Post: #2
 informach Member Posts: 109 Joined: Jul 2015
RE: Kronecker Product?
Hi!, DrD :
You can use, for calculate matrices, with Hadamard, as …
Syntax :
From … User_Guide_EN_2018_01_12_1.pdf (page 475).
02-17-2019, 05:48 PM
Post: #3
 DrD Senior Member Posts: 1,117 Joined: Feb 2014
RE: Kronecker Product?
(02-17-2019 03:47 PM)informach Wrote:  Hi!, DrD :
You can use, for calculate matrices, with Hadamard, as …
Syntax :
From … User_Guide_EN_2018_01_12_1.pdf (page 475).

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]
02-17-2019, 07:52 PM (This post was last modified: 02-17-2019 08:01 PM by Didier Lachieze.)
Post: #4
 Didier Lachieze Senior Member Posts: 1,156 Joined: Dec 2013
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
02-17-2019, 08:06 PM
Post: #5
 DrD Senior Member Posts: 1,117 Joined: Feb 2014
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!
02-18-2019, 08:58 AM
Post: #6
 Didier Lachieze Senior Member Posts: 1,156 Joined: Dec 2013
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
02-18-2019, 10:26 AM
Post: #7
 DrD Senior Member Posts: 1,117 Joined: Feb 2014
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-
 « Next Oldest | Next Newest »

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