randorth: Random orthogonal matrix

Description Usage Arguments Details Value Author(s) References Examples

Description

Generation of a random orthogonal n x n matrix.

Usage

1
randorth(n, type = c("orthonormal", "unitary"), I.matrix = FALSE)

Arguments

n

numeric of length 1 defining the dimensions of the n x n square matrix.

type

Either "orthonormal" or "unitary" defining whether a real orthonormal matrix or a complex unitary matrix should be returned.

I.matrix

If TRUE, the identity matrix is returned.

Details

A random orthogonal matrix R is generated in order that t(R) (for "orthonormal") or Conj(t(R)) (for "unitary") equals the inverse matrix of R.

This function was adapted from the pracma package (pracma::randortho).

The random orthogonal matrices are distributed with Haar measure over O(n), where O(n) is the set of orthogonal matrices of order n. The random orthogonal matrices are basically distributed "uniformly" in the space of random orthogonal matrices of dimension n x n. See also the Examples and \insertCiteStewart1980a,Mezzadri2007randRotation.

Value

A random orthogonal matrix of dimension n x n.

Author(s)

Peter Hettegger

References

\insertAllCited

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# The following example shows the orthogonality of the random orthogonal matrix:
R1 <- randorth(4)
zapsmall(t(R1) %*% R1)

R1 <- randorth(4, "unitary")
zapsmall(Conj(t(R1)) %*% R1)

# The following example shows the distribution of 2-dimensional random orthogonal vectors
# on the unit circle.
tmp1 <- vapply(1:400, function(i)randorth(2)[,1], numeric(2))
plot(t(tmp1), xlab = "x", ylab = "y")

randRotation documentation built on April 14, 2021, 6:01 p.m.