NAG FL Interface
g05pxf (matrix_​orthog)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

g05pxf generates a random orthogonal matrix.

2 Specification

Fortran Interface
Subroutine g05pxf ( side, init, m, n, state, a, lda, ifail)
Integer, Intent (In) :: m, n, lda
Integer, Intent (Inout) :: state(*), ifail
Real (Kind=nag_wp), Intent (Inout) :: a(lda,n)
Character (1), Intent (In) :: side, init
C Header Interface
#include <nag.h>
void  g05pxf_ (const char *side, const char *init, const Integer *m, const Integer *n, Integer state[], double a[], const Integer *lda, Integer *ifail, const Charlen length_side, const Charlen length_init)
The routine may be called by the names g05pxf or nagf_rand_matrix_orthog.

3 Description

g05pxf pre- or post-multiplies an m×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 x1,x2,,xn-1 follow independent multinormal distributions with zero mean and variance Iσ2 and dimensions n,n-1,,2; let Hj=diag(Ij-1,Hj*), where Ij-1 is the identity matrix and Hj* is the Householder transformation that reduces xj to rjje1, e1 being the vector with first element one and the remaining elements zero and rjj being a scalar, and let D=diag(sign(r11),sign(r22),,sign(rnn)). Then the product U=DH1H2Hn-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 routines g05kff (for a repeatable sequence if computed sequentially) or g05kgf (for a non-repeatable sequence) must be called prior to the first call to g05pxf.

4 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

5 Arguments

1: side Character(1) Input
On entry: indicates whether the matrix A is multiplied on the left or right by the random orthogonal matrix U.
side='L'
The matrix A is multiplied on the left, i.e., premultiplied.
side='R'
The matrix A is multiplied on the right, i.e., post-multiplied.
Constraint: side='L' or 'R'.
2: init Character(1) Input
On entry: indicates whether or not a should be initialized to the identity matrix.
init='I'
a is initialized to the identity matrix.
init='N'
a is not initialized and the matrix A must be supplied in a.
Constraint: init='I' or 'N'.
3: m Integer Input
On entry: m, the number of rows of the matrix A.
Constraints:
  • if side='L', m>1;
  • otherwise m1.
4: n Integer Input
On entry: n, the number of columns of the matrix A.
Constraints:
  • if side='R', n>1;
  • otherwise n1.
5: state(*) Integer array Communication Array
Note: the actual argument supplied must be the array state supplied to the initialization routines g05kff or g05kgf.
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
6: a(lda,n) Real (Kind=nag_wp) array Input/Output
On entry: if init='N', a must contain the matrix A.
On exit: the matrix UA when side='L' or the matrix A U when side='R'.
7: lda Integer Input
On entry: the first dimension of the array a as declared in the (sub)program from which g05pxf is called.
Constraint: ldam.
8: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or −1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, side is not valid: side=value.
ifail=2
On entry, init is not valid: init=value.
ifail=3
On entry, side=value, m=value.
Constraint: if side='L', m>1; otherwise m1.
ifail=4
On entry, side=value, n=value.
Constraint: if side='R', n>1; otherwise n1.
ifail=5
On entry, state vector has been corrupted or not initialized.
ifail=7
On entry, lda=value and m=value.
Constraint: ldam.
ifail=8
On entry, side=value, m=value.
Constraint: if side='L', m>1; otherwise m1.
On entry, side=value, n=value.
Constraint: if side='R', n>1; otherwise n1.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

The maximum error in UT U should be a modest multiple of machine precision (see Chapter X02).

8 Parallelism and Performance

g05pxf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g05pxf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

None.

10 Example

Following initialization of the pseudorandom number generator by a call to g05kff, a 4×4 orthogonal matrix is generated using the init='I' option and the result printed.

10.1 Program Text

Program Text (g05pxfe.f90)

10.2 Program Data

Program Data (g05pxfe.d)

10.3 Program Results

Program Results (g05pxfe.r)