On 12/30/2012 04:38 AM, Ren? Grognard wrote:
> /* We need the tensor product of matrices */
> /* Tensor Product of Matrices */
>
> tp(A,B):=
> block([n,n1,n2,m,m1,m2,p1,p2,C],
> n:matrix_size(A), n1:first(n), n2:second(n),
> m:matrix_size(B), m1:first(m), m2:second(m),
> p1:n1*m1, p2:n2*m2,
> C:zeromatrix(p1,p2),
> for i1:1 thru n1 do
> for i2:1 thru n2 do
> for j1:1 thru m1 do
> for j2:1 thru m2 do
> C[(i1-1)*m1+j1,(i2-1)*m2+j2]:A[i1,i2]*B[j1,j2],
> return(C))$
>
Hi,
if you'd like to see another way to get the same result in Maxima, here
it is:
tp(m1,m2):= block ([rows:[],row:[]],
local(c),
for i thru length (m1) do
for j thru length (m2) do
(row: [],
for c in first (row (m1,i)) do
row: append (row, c*first (row (m2,j))),
rows: endcons (row, rows)),
apply (matrix, rows))$
but, as Barton Willis has said, that product is already implemented in
Maxima as kronecker_product(A,B)
You might also be interested in this:
tp ([matrices]) := lreduce (kronecker_product, matrices)$
which allows you to make the tensor product of any number of matrices.
tp(A)
tp(A,B)
tp(A,B,C)
...
Best regards,
Jaime