Generate a random rotation matrix, i.e., a matrix c("", "\n", "P=(p[i,j]),i=1,ldots,p,j=1,ldots,p,")
which satisfies
a) P∗P′=I,
b) P′∗P=I,
c) det(P)=1.
Details
For dim = 2, p[2,1]
(sin(theta)) is generated from Unif(0, 1) and the rest computed as follows: c("", "\n", "p[1,1]=p[2,2]=sqrt(1−p[2,1]2)")
(cos(theta)) and p[1,2]=p[2,1]
(−sin(theta)).
For dim> 2, the matrix P is generated in the following steps:
Generate a pxp matrix A with independent Unif(0, 1) elements and check whether A
is of full rank p.
Computes a QR decomposition of A, i.e., A=QR where Q satisfies Q∗Q′=I, Q′∗Q=I, det(Q)=(−1)p+1, and columns of Q spans the linear space generated by the columns of A.
For odd dim, return matrix Q. For even dim, return corrected matrix Q to satisfy the determinant condition.
rRotationMatrix(n, dim)
Arguments
n: number of matrices to generate.
dim: dimension of a generated matrix/matrices.
Returns
For n=1, a matrix is returned.
For n>1, a list of matrices is returned.
References
Golub, G. H. and Van Loan, C. F. (1996, Sec. 5.1). Matrix Computations. Third Edition. Baltimore: The Johns Hopkins University Press.