randorth {randRotation}R Documentation

Random orthogonal matrix

Description

Generation of a random orthogonal n x n matrix.

Usage

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 (Stewart 1980; Mezzadri 2007).

Value

A random orthogonal matrix of dimension n x n.

Author(s)

Peter Hettegger

References

Mezzadri F (2007). “How to generate random matrices from the classical compact groups.” Notices of the American Mathematical Society, 54(5), 592–604. ISSN 1088-9477, 0609050, http://arxiv.org/abs/0609050.

Stewart GW (1980). “The Efficient Generation of Random Orthogonal Matrices with an Application to Condition Estimators.” SIAM Journal on Numerical Analysis. ISSN 0036-1429, doi: 10.1137/0717034, https://doi.org/10.1137/0717034.

Examples


# 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")


[Package randRotation version 1.4.0 Index]