Bill Allombert on Tue, 02 Apr 2024 21:28:32 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: kronecker product of matrices


On Tue, Apr 02, 2024 at 02:31:00PM -0400, Max Alekseyev wrote:
> Does PARI/GP provide functionality for Kronecker (tensor) products of
> matrices?
> I could not find anything upon a quick search.
> If such functionality is missing, can it be added to future versions?
> 
> For now, I use a custom function:
> 
> { matkron(A,B) = my(sa=matsize(A), sb=matsize(B)); matrix(sa[1]*sb[1],
> sa[2]*sb[2], i, j, A[(i-1)\sb[1]+1,(j-1)\sb[2]+1] *
> B[(i-1)%sb[1]+1,(j-1)%sb[2]+1]); }

You can use matconcat:

matk(A,B)=matconcat(apply(x->x*B,A))

Cheers,
Bill.