Skip to content

Instantly share code, notes, and snippets.

@anirudhjayaraman
Created December 14, 2015 15:34
Show Gist options
  • Save anirudhjayaraman/f663babdb1ea4ff7ced1 to your computer and use it in GitHub Desktop.
Save anirudhjayaraman/f663babdb1ea4ff7ced1 to your computer and use it in GitHub Desktop.
Solution to Problem 13, Section 2.7 Linear Algebra (Gilbert Strang)
% Solution for part (a)
p = permMatrices(3);
n = size(p,3); % number of permutation matrices
v = zeros(n,1); % vector of zeros with dimension equalling number of permutation matrices
% check for permutation matrices other than identity matrix with 3rd power equalling identity matrix
for i = 1:n
if p(:,:,i)^3 == eye(3)
v(i,1) = 1;
end
end
v(1,1) = 0; % exclude identity matrix
ans1 = p(:,:,v == 1)
% Solution for part (b)
P = permMatrices(4);
m = size(P,3); % number of permutation matrices
t = zeros(m,1); % vector of zeros with dimension equalling number of permutation matrices
% check for permutation matrices with 4th power equalling identity matrix
for i = 1:m
if P(:,:,i)^4 == eye(4)
t(i,1) = 1;
end
end
% print the permutation matrices
ans2 = P(:,:,t == 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment