Date: Jan 27, 2013 2:11 PM
Author: Nasser Abbasi
Subject: Re: need help

On 1/27/2013 10:44 AM, Muhammad Ramzan wrote:
> Hi everyone,
>
>
> I have two symbolic matrices;
>
> A = [1 p;0 1];
> B = [1 p;0 1-p];
>
> I have to calculate the tensor product of its all permutations as given below (obtained using npermutek function);
> i.e. tensor(A,A,A,A) and so on upto tensor(B,B,B,B) below;
>

>>> MAT = npermutek(['A' 'B'],4)
>
> MAT =
>
> AAAA
> AAAB

..
> BBAB
>
> Now how can I pick from MAT the index/matrices AAAA, ......BBBB for



long version, feel free to optimse

-------------------------------------
syms p
A = [1 p;0 1];
B = [1 p;0 1-p];

mat = npermutek(['A' 'B'],4);

for i=1:length(mat)
a=eval(sym(mat(i,1)));
b=eval(sym(mat(i,2)));
c=eval(sym(mat(i,3)));
d=eval(sym(mat(i,3)));
kron(kron(kron(a,b),c),d)
end
------------------------------------

answer for first row AAAA is


[ 1, p, p, p^2, p, p^2, p^2, p^3, p, p^2, p^2, p^3, p^2, p^3, p^3, p^4]
[ 0, 1, 0, p, 0, p, 0, p^2, 0, p, 0, p^2, 0, p^2, 0, p^3]
[ 0, 0, 1, p, 0, 0, p, p^2, 0, 0, p, p^2, 0, 0, p^2, p^3]
[ 0, 0, 0, 1, 0, 0, 0, p, 0, 0, 0, p, 0, 0, 0, p^2]
[ 0, 0, 0, 0, 1, p, p, p^2, 0, 0, 0, 0, p, p^2, p^2, p^3]
[ 0, 0, 0, 0, 0, 1, 0, p, 0, 0, 0, 0, 0, p, 0, p^2]
[ 0, 0, 0, 0, 0, 0, 1, p, 0, 0, 0, 0, 0, 0, p, p^2]
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, p]
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, p, p, p^2, p, p^2, p^2, p^3]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, p, 0, p, 0, p^2]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, p, 0, 0, p, p^2]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, p]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, p, p, p^2]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, p]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, p]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]

--Nasser