NAG Library Routine Document
F01BLF
1 Purpose
F01BLF calculates the rank and pseudoinverse of an $m$ by $n$ real matrix, $m\ge n$, using a $QR$ factorization with column interchanges.
2 Specification
SUBROUTINE F01BLF ( 
M, N, T, A, LDA, AIJMAX, IRANK, INC, D, U, LDU, DU, IFAIL) 
INTEGER 
M, N, LDA, IRANK, INC(N), LDU, IFAIL 
REAL (KIND=nag_wp) 
T, A(LDA,N), AIJMAX(N), D(M), U(LDU,N), DU(N) 

3 Description
Householder's factorization with column interchanges is used in the decomposition
$F=QU$, where
$F$ is
$A$ with its columns permuted,
$Q$ is the first
$r$ columns of an
$m$ by
$m$ orthogonal matrix and
$U$ is an
$r$ by
$n$ uppertrapezoidal matrix of rank
$r$. The pseudoinverse of
$F$ is given by
$X$ where
If the matrix is found to be of maximum rank,
$r=n$,
$U$ is a nonsingular
$n$ by
$n$ uppertriangular matrix and the pseudoinverse of
$F$ simplifies to
$X={U}^{1}{Q}^{\mathrm{T}}$. The transpose of the pseudoinverse of
$A$ is overwritten on
$A$.
4 References
Peters G and Wilkinson J H (1970) The least squares problem and pseudoinverses Comput. J. 13 309–316
Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag
5 Parameters
 1: $\mathrm{M}$ – INTEGERInput
 2: $\mathrm{N}$ – INTEGERInput

On entry: $m$ and $n$, the number of rows and columns in the matrix $A$.
Constraint:
${\mathbf{M}}\ge {\mathbf{N}}$.
 3: $\mathrm{T}$ – REAL (KIND=nag_wp)Input

On entry: the tolerance used to decide when elements can be regarded as zero (see
Section 9).
 4: $\mathrm{A}\left({\mathbf{LDA}},{\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On entry: the $m$ by $n$ rectangular matrix $A$.
On exit: the transpose of the pseudoinverse of $A$.
 5: $\mathrm{LDA}$ – INTEGERInput

On entry: the first dimension of the array
A as declared in the (sub)program from which F01BLF is called.
Constraint:
${\mathbf{LDA}}\ge {\mathbf{M}}$.
 6: $\mathrm{AIJMAX}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit:
${\mathbf{AIJMAX}}\left(i\right)$ contains the element of largest modulus in the reduced matrix at the
$i$th stage. If
$r<n$, then only the first
$r+1$ elements of
AIJMAX have values assigned to them; the remaining elements are unused. The ratio
${\mathbf{AIJMAX}}\left(1\right)/{\mathbf{AIJMAX}}\left(r\right)$ usually gives an indication of the condition number of the original matrix (see
Section 9).
 7: $\mathrm{IRANK}$ – INTEGEROutput

On exit:
$r$, the rank of
$A$ as determined using the tolerance
T.
 8: $\mathrm{INC}\left({\mathbf{N}}\right)$ – INTEGER arrayOutput

On exit: the record of the column interchanges in the Householder factorization.
 9: $\mathrm{D}\left({\mathbf{M}}\right)$ – REAL (KIND=nag_wp) arrayWorkspace
 10: $\mathrm{U}\left({\mathbf{LDU}},{\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayWorkspace

 11: $\mathrm{LDU}$ – INTEGERInput

On entry: the first dimension of the array
U as declared in the (sub)program from which F01BLF is called.
Constraint:
${\mathbf{LDU}}\ge {\mathbf{N}}$.
 12: $\mathrm{DU}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayWorkspace

 13: $\mathrm{IFAIL}$ – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
$0$.
When the value $\mathbf{1}\text{ or}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$

Inverse not found, due to an incorrect determination of
IRANK (see
Section 9).
 ${\mathbf{IFAIL}}=2$

Invalid tolerance, due to
(i) 
T is negative, ${\mathbf{IRANK}}=1$; 
(ii) 
T too large, ${\mathbf{IRANK}}=0$; 
(iii) 
T too small, ${\mathbf{IRANK}}>0$. 
 ${\mathbf{IFAIL}}=3$

On entry,  ${\mathbf{M}}<{\mathbf{N}}$. 
 ${\mathbf{IFAIL}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
 ${\mathbf{IFAIL}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
 ${\mathbf{IFAIL}}=999$
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
For most matrices the pseudoinverse is the best possible having regard to the condition of
$A$ and the choice of
T. Note that only the singular value decomposition method can be relied upon to give maximum accuracy for the precision of computation used and correct determination of the condition of a matrix (see
Wilkinson and Reinsch (1971)).
The computed factors
$Q$ and
$U$ satisfy the relation
$QU=F+E$ where
in which
$c$ is a modest function of
$m$ and
$n$,
$\eta $ is the value of
T, and
$\epsilon $ is the
machine precision.
8 Parallelism and Performance
Not applicable.
The time taken by F01BLF is approximately proportional to $mnr$.
The most difficult practical problem is the determination of the rank of the matrix (see pages 314–315 of
Peters and Wilkinson (1970)); only the singular value decomposition method gives a reliable indication of rank deficiency (see pages 134–151 of
Wilkinson and Reinsch (1971) and
F08KBF (DGESVD)). In F01BLF a tolerance,
T, is used to recognize ‘zero’ elements in the remaining matrix at each step in the factorization. The value of
T should be set at
$n$ times the bound on possible errors in individual elements of the original matrix. If the elements of
$A$ vary widely in their orders of magnitude, of course this presents severe difficulties. Sound decisions can only be made by somebody who appreciates the underlying physical problem.
If the condition number of $A$ is ${10}^{p}$ we expect to get $p$ figures wrong in the pseudoinverse. An estimate of the condition number is usually given by ${\mathbf{AIJMAX}}\left(1\right)/{\mathbf{AIJMAX}}\left(r\right)$.
10 Example
A complete program follows which outputs the maximum of the moduli of the ‘remaining’ elements at each step in the factorization, the rank, as determined by the given value of
T, and the transposed pseudoinverse. Data and results are given for an example which is a
$6$ by
$5$ matrix of deficient rank in which the last column is a linear combination of the other four. Setting
T to
$\epsilon $ times the norm of the matrix, the rank is correctly determined as
$4$ and the pseudoinverse is computed to full implementation accuracy.
10.1 Program Text
Program Text (f01blfe.f90)
10.2 Program Data
Program Data (f01blfe.d)
10.3 Program Results
Program Results (f01blfe.r)