Permutation Matrix on a Vector

조회 수: 7 (최근 30일)
Raymond's Group Lee
Raymond's Group Lee 2011년 3월 19일
How can I compute the permutation matrix without using loop?
Let
V = Original n-vector
Vstar = Permuted n-vector
P = (n x n) Permutation Matrix
such that
P * V = Vstar.
Given V and Vstar, how can I determine P without using loop?

채택된 답변

Matt Fig
Matt Fig 2011년 3월 19일
If I understand your question correctly, there is no unique solution. You can understand this by looking at a 2-by-2 system.
P = [a b;c d]
V = [e;f]
Vs = [g;h]
Now from P*V = Vs, we know that:
a*e + b*f = g
c*e + d*f = h
Thus if V and Vs are known, then e, f, g, and h are known. But we still have two equations and four unknowns ( a , b, c, and d ). So unless there are two more ways of limiting the choices for the four unknowns, we are stuck.
For a larger system, the problem only gets worse.
  댓글 수: 2
Jan
Jan 2011년 3월 19일
But in addition we have the term "permutation matrix". This means that a,b,c,d are 0 or 1 with only one 1 per row and column.
Raymond's Group Lee
Raymond's Group Lee 2011년 3월 19일
Matt
You are right. I should be more careful when I define my permutation matrix. I would like my permutation matrix to have one 1 for every row and every column, with the remaining entries being 0.
Please refer to Wikipedia:
http://en.wikipedia.org/wiki/Permutation_matrix
Thanks.
Raymond

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2011년 3월 19일
If the values of V are unique:
V = (1:5)';
Vstar = V(randperm(length(V)));
P = bsxfun(@eq, V', Vstar);
isequal(P * V, Vstar)
  댓글 수: 4
Matt Fig
Matt Fig 2011년 3월 19일
Jan, is this faster (though less comprehensible) on a newer version? On my 2007a, it is about 40% faster for N = 5000;
[VI,VI] = sort(V); % If V is sorted already, then skip this.
[VsI,VsI] = sort(Vstar);
P2 = zeros(N);
P2(VsI+(VI-1)*N) = 1;
Jan
Jan 2011년 3월 19일
Surprising! Two SORT compared to a simple comparison? BSXFUN seems to be worth to be improved. A further acceleration: P2 = zeros(N, N, 'uint8');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by