function Q = rand_orthogonal(n, special)

%Generates a random n-dimensional orthogonal matrix Q.
%Q has determinant 1 if special==true.

A = randn(n,n);
Q = expm(A-A');
if(special)
	if(det(Q)<1)
		Q = -Q;
	end
end
