Home > manopt > manifolds > rotations > randskew.m

# randskew

## PURPOSE

Generates random skew symmetric matrices with normal entries.

## SYNOPSIS

function S = randskew(n, N)

## DESCRIPTION

``` Generates random skew symmetric matrices with normal entries.

function S = randskew(n)
function S = randskew(n, N)

S is an n-by-n-by-N array where each slice S(:, :, i) for i = 1..N is a
random skew-symmetric matrix with upper triangular entries distributed
independently following a normal distribution (Gaussian, zero mean, unit
variance).

By default, N = 1.

## CROSS-REFERENCE INFORMATION

This function calls:
• multitransp Transpose the matrix slices of an N-D array (no complex conjugate)
This function is called by:
• essentialfactory Manifold structure to optimize over the space of essential matrices.
• randherm Generates random Hermitian matrices with normal entries.
• randskewh Generates random skew Hermitian matrices with normal entries.
• rotationsfactory Returns a manifold structure to optimize over rotation matrices.

## SOURCE CODE

```0001 function S = randskew(n, N)
0002 % Generates random skew symmetric matrices with normal entries.
0003 %
0004 % function S = randskew(n)
0005 % function S = randskew(n, N)
0006 %
0007 % S is an n-by-n-by-N array where each slice S(:, :, i) for i = 1..N is a
0008 % random skew-symmetric matrix with upper triangular entries distributed
0009 % independently following a normal distribution (Gaussian, zero mean, unit
0010 % variance).
0011 %
0012 % By default, N = 1.
0013 %
0015
0016 % This file is part of Manopt: www.manopt.org.
0017 % Original author: Nicolas Boumal, Sept. 25, 2012.
0018 % Contributors:
0019 % Change log:
0020 %       June 19, 2019 (NB):
0021 %           Now handles the case n = 1 properly.
0022
0023     if nargin < 2
0024         N = 1;
0025     end
0026
0027     if n == 1
0028         S = zeros(1, 1, N);
0029         return;
0030     end
0031
0032     % Subindices of the (strictly) upper triangular entries of an n-by-n
0033     % matrix
0034     [I, J] = find(triu(ones(n), 1));
0035
0036     K = repmat(1:N, n*(n-1)/2, 1);
0037
0038     % Indices of the strictly upper triangular entries of all N slices of
0039     % an n-by-n-by-N matrix
0040     L = sub2ind([n n N], repmat(I, N, 1), repmat(J, N, 1), K(:));
0041
0042     % Allocate memory for N random skew matrices of size n-by-n and
0043     % populate each upper triangular entry with a random number following a
0044     % normal distribution and copy them with opposite sign on the
0045     % corresponding lower triangular side.
0046     S = zeros(n, n, N);
0047     S(L) = randn(size(L));
0048     S = S - multitransp(S);
0049
0050 end```

Generated on Fri 30-Sep-2022 13:18:25 by m2html © 2005