Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Nasser Abbasi

Posts: 5,596
Registered: 2/7/05
Re: need help
Posted: Jan 27, 2013 2:11 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic 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
Read Re: need help
Nasser Abbasi
1/28/13
Read Re: need help
Nasser Abbasi

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.