g05px generates a random orthogonal matrix.

# Syntax

C#
```public static void g05px(
string side,
string init,
int m,
int n,
G05..::..G05State g05state,
double[,] a,
out int ifail
)```
Visual Basic
```Public Shared Sub g05px ( _
side As String, _
init As String, _
m As Integer, _
n As Integer, _
g05state As G05..::..G05State, _
a As Double(,), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g05px(
String^ side,
String^ init,
int m,
int n,
G05..::..G05State^ g05state,
array<double,2>^ a,
[OutAttribute] int% ifail
)```
F#
```static member g05px :
side : string *
init : string *
m : int *
n : int *
g05state : G05..::..G05State *
a : float[,] *
ifail : int byref -> unit
```

#### Parameters

side
Type: System..::..String
On entry: indicates whether the matrix $A$ is multiplied on the left or right by the random orthogonal matrix $U$.
${\mathbf{side}}=\text{"L"}$
The matrix $A$ is multiplied on the left, i.e., premultiplied.
${\mathbf{side}}=\text{"R"}$
The matrix $A$ is multiplied on the right, i.e., post-multiplied.
Constraint: ${\mathbf{side}}=\text{"L"}$ or $\text{"R"}$.
init
Type: System..::..String
On entry: indicates whether or not a should be initialized to the identity matrix.
${\mathbf{init}}=\text{"I"}$
a is initialized to the identity matrix.
${\mathbf{init}}=\text{"N"}$
a is not initialized and the matrix $A$ must be supplied in a.
Constraint: ${\mathbf{init}}=\text{"I"}$ or $\text{"N"}$.
m
Type: System..::..Int32
On entry: $m$, the number of rows of the matrix $A$.
Constraints:
• if ${\mathbf{side}}=\text{"L"}$, ${\mathbf{m}}>1$;
• otherwise ${\mathbf{m}}\ge 1$.
n
Type: System..::..Int32
On entry: $n$, the number of columns of the matrix $A$.
Constraints:
• if ${\mathbf{side}}=\text{"R"}$, ${\mathbf{n}}>1$;
• otherwise ${\mathbf{n}}\ge 1$.
g05state
Type: NagLibrary..::..G05..::..G05State
An Object of type G05.G05State.
a
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{m}}$
On entry: if ${\mathbf{init}}=\text{"N"}$, a must contain the matrix $A$.
On exit: the matrix $UA$ when ${\mathbf{side}}=\text{"L"}$ or the matrix $AU$ when ${\mathbf{side}}=\text{"R"}$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

g05px pre- or post-multiplies an $m$ by $n$ matrix $A$ by a random orthogonal matrix $U$, overwriting $A$. The matrix $A$ may optionally be initialized to the identity matrix before multiplying by $U$, hence $U$ is returned. $U$ is generated using the method of Stewart (1980). The algorithm can be summarised as follows.
Let ${x}_{1},{x}_{2},\dots ,{x}_{n-1}$ follow independent multinormal distributions with zero mean and variance $I{\sigma }^{2}$ and dimensions $n,n-1,\dots ,2$; let ${H}_{j}=\mathrm{diag}\left({I}_{j-1},{H}_{j}^{*}\right)$, where ${I}_{j-1}$ is the identity matrix and ${H}_{j}^{*}$ is the Householder transformation that reduces ${x}_{j}$ to ${r}_{jj}{e}_{1}$, ${e}_{1}$ being the vector with first element one and the remaining elements zero and ${r}_{jj}$ being a scalar, and let $D=\mathrm{diag}\left(\mathrm{sign}\left({r}_{11}\right),\mathrm{sign}\left({r}_{22}\right),\dots ,\mathrm{sign}\left({r}_{nn}\right)\right)$. Then the product $U=D{H}_{1}{H}_{2}\dots {H}_{n-1}$ is a random orthogonal matrix distributed according to the Haar measure over the set of orthogonal matrices of $n$. See Theorem 3.3 in Stewart (1980).
One of the initialization methods (G05KFF not in this release) (for a repeatable sequence if computed sequentially) or (G05KGF not in this release) (for a non-repeatable sequence) must be called prior to the first call to g05px.

# References

Stewart G W (1980) The efficient generation of random orthogonal matrices with an application to condition estimates SIAM J. Numer. Anal. 17 403–409

# Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDA) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{side}}\ne \text{"L"}$ or $\text{"R"}$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{init}}\ne \text{"I"}$ or $\text{"N"}$.
${\mathbf{ifail}}=3$
 On entry, ${\mathbf{m}}<1$.
${\mathbf{ifail}}=4$
 On entry, ${\mathbf{n}}<1$.
${\mathbf{ifail}}=5$
 On entry, state vector was not initialized or has been corrupted.
${\mathbf{ifail}}=8$
On entry, an orthogonal matrix of dimension $1$ has been requested.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

The maximum error in ${U}^{\mathrm{T}}U$ should be a modest multiple of machine precision (see X02 class).

None.

None.