Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: need help
Replies: 3   Last Post: Jan 28, 2013 7:47 AM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Nasser Abbasi Posts: 6,654 Registered: 2/7/05
Re: need help
Posted: Jan 27, 2013 2:11 PM
 Plain Text Reply

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

Date Subject Author
1/27/13 Nasser Abbasi
1/28/13 Nasser Abbasi

© The Math Forum at NCTM 1994-2017. All Rights Reserved.