MATLAB: How to taker power of a permutaion matrix permutaion matrix Hi ,I want to find the power of a permutation matrix, i.e A=(1 2 3;3 2 1) is a permutation matrix and I want to find (1 2 3; 3 2 1)^5 .How to do this in matlab Best Answer You have 2 ways to compute it, from the permutation itself, or using the permutation matrix then raise a power of it.% Generate a random test permutation[~,p]=sort(rand(1,10)); % in you case it's [3 2 1], the second row of your A% Permutation matrix p0 = 1:length(p);A = accumarray([p(:) p0(:)],1);% raise powern = 5;Apn = A^n% apply the permutation n times pn = p0;for k=1:n pn = pn(p);endAn = accumarray([pn(:) p0(:)],1)% Check both gives the same result isequal(Apn,An) Related SolutionsMATLAB: Sorting matrix sortrows(a) MATLAB: Column circular permutaion on a matrix Try thisA = [ 1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16];B = [9 6 15 12; 13 10 3 16; 1 14 7 4; 5 2 11 8];shift = [2, 1, 3, 2];C = A; % make a copyfor i=1:numel(shift) C(:,i) = circshift(C(:,i), -shift(i));endResult>> isequal(B, C)ans = logical 1 Related QuestionHow to find index of first 3 maximum number in matrixHow to use meshgrid in a loopHow to sort the elements of an array within a given rangeHow to plot matrix inside for loop
Best Answer