% ShowOrthogonal
% Illustrates some things about an orthogonal matrix.

format short
% Examples...

% A 2x2 rotation...
theta = 2*pi*rand();
Q = [ cos(theta) sin(theta);...
-sin(theta) cos(theta)]

% A 2x2 reflection...
Q = [ cos(theta) sin(theta);...
sin(theta) -cos(theta)]

% A permutation matrix...
I = eye(5,5);
P = I(randperm(5),:)

% Properties...
[Q,R] = qr(randn(4,4));
% Q is a random 4x4 matrix
% Confirm that Q(:,i)'*Q(:,j) = 1 if i==j and 0 otherwise...
for i=1:4
for j=1:4
alfa = Q(:,i)'*Q(:,j);
fprintf('Q(:,%1d)''*Q(:,%1d) = %19.16f\n',i,j,alfa)
end
end
% Since det(I) = det(Q'*Q) = det(Q)det(Q') = det(Q)^2, det(Q) = +1 or -1