HP Forums
Matrix tensor product - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Matrix tensor product (/thread-10242.html)



Matrix tensor product - Akrone - 02-25-2018 05:02 PM

Hey guys, i'm looking for a way to "properly" do a tensor product.
By properly i mean: [0, 1] tensor [1, 0] = [0, 1, 0, 0]
Precisely i want the calculator to keep the dimensions, and he don't, which cause me troubles in cases like:

x x x x
x x x x
x x x x . tensor([0, 1], [1, 0])
x x x x

because the tensor's returned matrix is 1x3.

Thanks ! Smile


RE: Matrix tensor product - DrD - 06-27-2019 07:28 PM

(02-25-2018 05:02 PM)Akrone Wrote:  Hey guys, i'm looking for a way to "properly" do a tensor product.
By properly i mean: [0, 1] tensor [1, 0] = [0, 1, 0, 0]
Precisely i want the calculator to keep the dimensions, and he don't, which cause me troubles in cases like:

x x x x
x x x x
x x x x . tensor([0, 1], [1, 0])
x x x x

because the tensor's returned matrix is 1x3.

Thanks ! Smile

I know this bus has long since left the station, but:

Thanks to Didier Lachieze, his kronecker program will accomplish the task. Please note that the result for the two vectors in the OP's example is not correct, it should be: [0,0,1,0].

The tensor product is useful in the field of quantum mechanics, which is where I encountered it, (today), and hence this late reply!

Code:

//        kronecker(a,b)
//        Didier Lachieze 
//          2/17/2019

#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

-Dale-