-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrot.m
More file actions
56 lines (50 loc) · 1.15 KB
/
rot.m
File metadata and controls
56 lines (50 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
% Produce rotation matrix.
% Details: input is dimension n of vector space for rotation.
% A random permutation of 1:n is generated and stored as indx.
% Then for i=1,...,n-1, a rotation of pi/4 rad between indx(i)
% and indx(i+1) is performed.
% The resulting rotation matrix Q is output.
% Carl Ehrett 2017
function [Q] = rot(n)
rindx = randperm(n);
Q = eye(n);
stot=sqrt(2)/2;
msg=0;
for ii = 1 : (n-1)
rii = rindx(ii);
rjj = rindx(ii+1);
q = speye(n);
q(rii,rii) = stot;
q(rjj,rjj) = stot;
q(rjj,rii) = stot;
q(rii,rjj) = -stot;
Q = q * Q;
fprintf(repmat('\b',1,msg));
msg=fprintf('Current column: %g/%g\n', ii,n);
end
end
% Saving the below as backup
% function [Q] = rot(n)
%
% rindx = randperm(n);
%
% Q = eye(n);
% stot=sqrt(2)/2;
% msg=0;
%
% for ii = 1 : (n-1)
% rii = rindx(ii);
% for jj = (ii+1):n
% rjj = rindx(jj);
% q = speye(n);
% q(rii,rii) = stot;
% q(rjj,rjj) = stot;
% q(rjj,rii) = stot;
% q(rii,rjj) = -stot;
% Q = q * Q;
% end
% fprintf(repmat('\b',1,msg));
% msg=fprintf('Current column: %g/%g\n', ii,n);
% end
%
% end