How to calculate permutation powers

조회 수: 1 (최근 30일)
lilly lord
lilly lord 2021년 7월 31일
댓글: lilly lord 2021년 8월 2일
I have to find higher powers of a permutation. For example if M is a given permutation , then to calculate M^11
M= [ 1 2 3 4 5 6 7 8 9 10; 3 6 8 1 2 4 5 7 10 9]
M^11 the answer should be [1:10;7 1 5 8 4 3 62 10 9];
The code below works well for small permutation but for large permutation and higher power gives error. If any one can help . Thanks in advance
inMat: The input permutation matrix
% n: The number of permutations
% M=[1 2 3 4 5 6; 3 4 1 5 6 2];
Temp=inMat;
Temp1=inMat;
rc=size(Temp);
outMat(1,:)=Temp(1,:);
for j=1:n
for i=1:rc(2)
r=Temp(:,i);
outMat(2,i)=Temp1(2,r(2));
end
Temp1=outMat;
end
  댓글 수: 2
dpb
dpb 2021년 8월 1일
For example if M is a given permutation , then to calculate M^11
M= [ 1 2 3 4 5 6 7 8 9 10; 3 6 8 1 2 4 5 7 10 9]
M^11 the answer should be [1:10;7 1 5 8 4 3 62 10 9];
I've no klew how you come up with the above as the answer???
Nor what power has to do with it given the sample code that is supposed to work ("for small permutation")...
Can't figure out what it's supposed to do as not everything is defined in the code snippet.
Image Analyst
Image Analyst 2021년 8월 1일
I agree with dpb (above). No idea how you came up with that answer, or what a "power" of a permutation is. All I know is that M is a matrix, not a permutation.
% M is a matrix, not a permutation of anything that we know of so far.
M = [1 2 3 4 5 6 7 8 9 10; 3 6 8 1 2 4 5 7 10 9]
% With the above M, the bottom row is a permutation of the top row.
% So actually each row is a permutation of the other row.
% Make a new matrix that is a permutation of M:
randomIndexes = randperm(numel(M))
M2 = reshape(M(randomIndexes), size(M))
You can see in the last line I made a permutation of your matrix M using randperm(). But I still have no idea what you mean by the "power" of it. Do you just want to raise it to the 11th power, like
M2 = M2 .^ 11;
????

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

채택된 답변

Bruno Luong
Bruno Luong 2021년 8월 1일
M= [ 1 2 3 4 5 6 7 8 9 10; 3 6 8 1 2 4 5 7 10 9]
M = 2×10
1 2 3 4 5 6 7 8 9 10 3 6 8 1 2 4 5 7 10 9
S=sparse(M(2,:),M(1,:),1);
[p11,~]=find(S^11);
M11= [M(1,:);p11']
M11 = 2×10
1 2 3 4 5 6 7 8 9 10 7 1 5 8 4 3 6 2 10 9
  댓글 수: 3
lilly lord
lilly lord 2021년 8월 2일
Thank u very much . Can u plz tell me how to take powers of disjoint cycles using the code u have shared.
lilly lord
lilly lord 2021년 8월 2일
Your answer solved my problem . Thank u . for powers of disjoint cycles i will ask as another question

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

추가 답변 (1개)

David Goodmanson
David Goodmanson 2021년 8월 2일
편집: David Goodmanson 2021년 8월 2일
Hi lilly,
Since the 1:n in the first row is just along for the ride, you don't have to carry it along in the calculation; you can just append it at the end. For the 11th power you have to use n=10 multplciations so it might be less confusing to redifine nnew = n+1 and use nnew-1 multiplications. Anyway, the inner do loop is equivalent to the following iterative mapping process:
n = 10;
inMat = [1:10;
3 6 8 1 2 4 5 7 10 9]
Temp=inMat;
Temp1=inMat;
rc=size(Temp);
outMat(1,:)=Temp(1,:);
for j=1:n
for i=1:rc(2)
r=Temp(:,i)
outMat(2,i)=Temp1(2,r(2));
end
Temp1=outMat;
end
outMat
% alterative
p0 = inMat(2,:);
p = p0;
for j = 1:n
p = p0(p);
end
outMat2 = [1:10; p]

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by