Add the random_orthogonal_matrix() function and its tests.
[octave.git] / random_orthogonal_matrix.m
1 function U = random_orthogonal_matrix(integerN)
2 %
3 % Generate a random orthogonal matrix.
4 %
5 % INPUT:
6 %
7 % - ``integerN`` -- The dimension of the resulting square matrix.
8 %
9 % OUTPUT:
10 %
11 % - ``U`` -- An orthogonal matrix of dimension integerN.
12 %
13 % REFERENCES:
14 %
15 % 1. G.W. Stewart, Efficient Generation of Random Orthogonal Matrices,
16 % SIAM J. Numer. Analysis, 1980, pp. 403--409, Section 3.
17 %
18
19 % We begin by computing a random matrix A.
20 A = rand(integerN);
21
22 % The Q-R decomposition of A will give us an orthogonal factor of A.
23 % See the reference for why this doesn't suck.
24 [U, R] = qr(A);
25 end