F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08RAF (DORCSD)

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

F08RAF (DORCSD) computes the CS decomposition of a real $m$ by $m$ orthogonal matrix $X$, partitioned into a $2$ by $2$ array of submatrices.

## 2  Specification

 SUBROUTINE F08RAF ( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, SIGNS, M, P, Q, X11, LDX11, X12, LDX12, X21, LDX21, X22, LDX22, THETA, U1, LDU1, U2, LDU2, V1T, LDV1T, V2T, LDV2T, WORK, LWORK, IWORK, INFO)
 INTEGER M, P, Q, LDX11, LDX12, LDX21, LDX22, LDU1, LDU2, LDV1T, LDV2T, LWORK, IWORK(M-min(P,M-P,Q,M-Q)), INFO REAL (KIND=nag_wp) X11(LDX11,*), X12(LDX12,*), X21(LDX21,*), X22(LDX22,*), THETA(min(P,M-P,Q,M-Q)), U1(LDU1,*), U2(LDU2,*), V1T(LDV1T,*), V2T(LDV2T,*), WORK(max(1,LWORK)) CHARACTER(1) JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, SIGNS
The routine may be called by its LAPACK name dorcsd.

## 3  Description

The $m$ by $m$ orthogonal matrix $X$ is partitioned as
 $X= X11 X12 X21 X22$
where ${X}_{11}$ is a $p$ by $q$ submatrix and the dimensions of the other submatrices ${X}_{12}$, ${X}_{21}$ and ${X}_{22}$ are such that $X$ remains $m$ by $m$.
The CS decomposition of $X$ is $X=U{\Sigma }_{p}{V}^{\mathrm{T}}$ where $U$, $V$ and ${\Sigma }_{p}$ are $m$ by $m$ matrices, such that
 $U= U1 0 0 U2$
is an orthogonal matrix containing the $p$ by $p$ orthogonal matrix ${U}_{1}$ and the $\left(m-p\right)$ by $\left(m-p\right)$ orthogonal matrix ${U}_{2}$;
 $V= V1 0 0 V2$
is an orthogonal matrix containing the $q$ by $q$ orthogonal matrix ${V}_{1}$ and the $\left(m-q\right)$ by $\left(m-q\right)$ orthogonal matrix ${V}_{2}$; and
 $Σp= I11 0 0 0 C 0 0 -S 0 0 0 -I12 0 0 I22 0 0 S C 0 0 I21 0 0$
contains the $r$ by $r$ non-negative diagonal submatrices $C$ and $S$ satisfying ${C}^{2}+{S}^{2}=I$, where $r=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,m-p,q,m-q\right)$ and the top left partition is $p$ by $q$.
The identity matrix ${I}_{11}$ is of order $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,q\right)-r$ and vanishes if $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,q\right)=r$.
The identity matrix ${I}_{12}$ is of order $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,m-q\right)-r$ and vanishes if $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,m-q\right)=r$.
The identity matrix ${I}_{21}$ is of order $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m-p,q\right)-r$ and vanishes if $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m-p,q\right)=r$.
The identity matrix ${I}_{22}$ is of order $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m-p,m-q\right)-r$ and vanishes if $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m-p,m-q\right)=r$.
In each of the four cases $r=p,q,m-p,m-q$ at least two of the identity matrices vanish.
The indicated zeros represent augmentations by additional rows or columns (but not both) to the square diagonal matrices formed by ${I}_{ij}$ and $C$ or $S$.
${\Sigma }_{p}$ does not need to be stored in full; it is sufficient to return only the values ${\theta }_{i}$ for $i=1,2,\dots ,r$ where ${C}_{ii}=\mathrm{cos}\left({\theta }_{i}\right)$ and ${S}_{ii}=\mathrm{sin}\left({\theta }_{i}\right)$.
The algorithm used to perform the complete $CS$ decomposition is described fully in Sutton (2009) including discussions of the stability and accuracy of the algorithm.

## 4  References

Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999) LAPACK Users' Guide (3rd Edition) SIAM, Philadelphia http://www.netlib.org/lapack/lug
Golub G H and Van Loan C F (2012) Matrix Computations (4th Edition) Johns Hopkins University Press, Baltimore
Sutton B D (2009) Computing the complete $CS$ decomposition Numerical Algorithms (Volume 50) 1017–1398 Springer US 33–65 http://dx.doi.org/10.1007/s11075-008-9215-6

## 5  Arguments

1:     $\mathrm{JOBU1}$ – CHARACTER(1)Input
On entry:
• if ${\mathbf{JOBU1}}=\text{'Y'}$, ${U}_{1}$ is computed;
• otherwise, ${U}_{1}$ is not computed.
2:     $\mathrm{JOBU2}$ – CHARACTER(1)Input
On entry:
• if ${\mathbf{JOBU2}}=\text{'Y'}$, ${U}_{2}$ is computed;
• otherwise, ${U}_{2}$ is not computed.
3:     $\mathrm{JOBV1T}$ – CHARACTER(1)Input
On entry:
• if ${\mathbf{JOBV1T}}=\text{'Y'}$, ${V}_{1}^{\mathrm{T}}$ is computed;
• otherwise, ${V}_{1}^{\mathrm{T}}$ is not computed.
4:     $\mathrm{JOBV2T}$ – CHARACTER(1)Input
On entry:
• if ${\mathbf{JOBV2T}}=\text{'Y'}$, ${V}_{2}^{\mathrm{T}}$ is computed;
• otherwise, ${V}_{2}^{\mathrm{T}}$ is not computed.
5:     $\mathrm{TRANS}$ – CHARACTER(1)Input
On entry:
• if ${\mathbf{TRANS}}=\text{'T'}$, $X$, ${U}_{1}$, ${U}_{2}$, ${V}_{1}^{\mathrm{T}}$ and ${V}_{2}^{\mathrm{T}}$ are stored in row-major order;
• otherwise, $X$, ${U}_{1}$, ${U}_{2}$, ${V}_{1}^{\mathrm{T}}$ and ${V}_{2}^{\mathrm{T}}$ are stored in column-major order.
6:     $\mathrm{SIGNS}$ – CHARACTER(1)Input
On entry:
• if ${\mathbf{SIGNS}}=\text{'O'}$, the lower-left block is made nonpositive (the other convention);
• otherwise, the upper-right block is made nonpositive (the default convention).
7:     $\mathrm{M}$ – INTEGERInput
On entry: $m$, the number of rows and columns in the orthogonal matrix $X$.
Constraint: ${\mathbf{M}}\ge 0$.
8:     $\mathrm{P}$ – INTEGERInput
On entry: $p$, the number of rows in ${X}_{11}$ and ${X}_{12}$.
Constraint: $0\le {\mathbf{P}}\le {\mathbf{M}}$.
9:     $\mathrm{Q}$ – INTEGERInput
On entry: $q$, the number of columns in ${X}_{11}$ and ${X}_{21}$.
Constraint: $0\le {\mathbf{Q}}\le {\mathbf{M}}$.
10:   $\mathrm{X11}\left({\mathbf{LDX11}},*\right)$ – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array X11 must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{P}}\right)$ if ${\mathbf{TRANS}}=\text{'T'}$, and at least ${\mathbf{Q}}$ otherwise.
On entry: the upper left partition of the orthogonal matrix $X$ whose CSD is desired.
On exit: contains details of the orthogonal matrix used in a simultaneous bidiagonalization process.
11:   $\mathrm{LDX11}$ – INTEGERInput
On entry: the first dimension of the array X11 as declared in the (sub)program from which F08RAF (DORCSD) is called.
Constraints:
• if ${\mathbf{TRANS}}=\text{'T'}$, ${\mathbf{LDX11}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{Q}}\right)$;
• otherwise ${\mathbf{LDX11}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{P}}\right)$.
12:   $\mathrm{X12}\left({\mathbf{LDX12}},*\right)$ – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array X12 must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{P}}\right)$ if ${\mathbf{TRANS}}=\text{'T'}$, and at least ${\mathbf{M}}-{\mathbf{Q}}$ otherwise.
On entry: the upper right partition of the orthogonal matrix $X$ whose CSD is desired.
On exit: contains details of the orthogonal matrix used in a simultaneous bidiagonalization process.
13:   $\mathrm{LDX12}$ – INTEGERInput
On entry: the first dimension of the array X12 as declared in the (sub)program from which F08RAF (DORCSD) is called.
Constraints:
• if ${\mathbf{TRANS}}=\text{'T'}$, ${\mathbf{LDX12}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{Q}}\right)$;
• otherwise ${\mathbf{LDX12}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{P}}\right)$.
14:   $\mathrm{X21}\left({\mathbf{LDX21}},*\right)$ – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array X21 must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{P}}\right)$ if ${\mathbf{TRANS}}=\text{'T'}$, and at least ${\mathbf{Q}}$ otherwise.
On entry: the lower left partition of the orthogonal matrix $X$ whose CSD is desired.
On exit: contains details of the orthogonal matrix used in a simultaneous bidiagonalization process.
15:   $\mathrm{LDX21}$ – INTEGERInput
On entry: the first dimension of the array X21 as declared in the (sub)program from which F08RAF (DORCSD) is called.
Constraints:
• if ${\mathbf{TRANS}}=\text{'T'}$, ${\mathbf{LDX21}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{Q}}\right)$;
• otherwise ${\mathbf{LDX21}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{P}}\right)$.
16:   $\mathrm{X22}\left({\mathbf{LDX22}},*\right)$ – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array X22 must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{P}}\right)$ if ${\mathbf{TRANS}}=\text{'T'}$, and at least ${\mathbf{M}}-{\mathbf{Q}}$ otherwise.
On entry: the lower right partition of the orthogonal matrix $X$ CSD is desired.
On exit: contains details of the orthogonal matrix used in a simultaneous bidiagonalization process.
17:   $\mathrm{LDX22}$ – INTEGERInput
On entry: the first dimension of the array X22 as declared in the (sub)program from which F08RAF (DORCSD) is called.
Constraints:
• if ${\mathbf{TRANS}}=\text{'T'}$, ${\mathbf{LDX22}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{Q}}\right)$;
• otherwise ${\mathbf{LDX22}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{P}}\right)$.
18:   $\mathrm{THETA}\left(\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{P}},{\mathbf{M}}-{\mathbf{P}},{\mathbf{Q}},{\mathbf{M}}-{\mathbf{Q}}\right)\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the values ${\theta }_{i}$ for $i=1,2,\dots ,r$ where $r=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,m-p,q,m-q\right)$. The diagonal submatrices $C$ and $S$ of ${\Sigma }_{p}$ are constructed from these values as
• $C=\mathrm{diag}\left(\mathrm{cos}\left({\mathbf{THETA}}\left(1\right)\right),\dots ,\mathrm{cos}\left({\mathbf{THETA}}\left(r\right)\right)\right)$ and
• $S=\mathrm{diag}\left(\mathrm{sin}\left({\mathbf{THETA}}\left(1\right)\right),\dots ,\mathrm{sin}\left({\mathbf{THETA}}\left(r\right)\right)\right)$.
19:   $\mathrm{U1}\left({\mathbf{LDU1}},*\right)$ – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array U1 must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{P}}\right)$ if ${\mathbf{JOBU1}}=\text{'Y'}$, and at least $1$ otherwise.
On exit: if ${\mathbf{JOBU1}}=\text{'Y'}$, U1 contains the $p$ by $p$ orthogonal matrix ${U}_{1}$.
20:   $\mathrm{LDU1}$ – INTEGERInput
On entry: the first dimension of the array U1 as declared in the (sub)program from which F08RAF (DORCSD) is called.
Constraint: if ${\mathbf{JOBU1}}=\text{'Y'}$, ${\mathbf{LDU1}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{P}}\right)$.
21:   $\mathrm{U2}\left({\mathbf{LDU2}},*\right)$ – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array U2 must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{P}}\right)$ if ${\mathbf{JOBU2}}=\text{'Y'}$, and at least $1$ otherwise.
On exit: if ${\mathbf{JOBU2}}=\text{'Y'}$, U2 contains the $m-p$ by $m-p$ orthogonal matrix ${U}_{2}$.
22:   $\mathrm{LDU2}$ – INTEGERInput
On entry: the first dimension of the array U2 as declared in the (sub)program from which F08RAF (DORCSD) is called.
Constraint: if ${\mathbf{JOBU2}}=\text{'Y'}$, ${\mathbf{LDU2}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{P}}\right)$.
23:   $\mathrm{V1T}\left({\mathbf{LDV1T}},*\right)$ – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array V1T must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{Q}}\right)$ if ${\mathbf{JOBV1T}}=\text{'Y'}$, and at least $1$ otherwise.
On exit: if ${\mathbf{JOBV1T}}=\text{'Y'}$, V1T contains the $q$ by $q$ orthogonal matrix ${{V}_{1}}^{\mathrm{T}}$.
24:   $\mathrm{LDV1T}$ – INTEGERInput
On entry: the first dimension of the array V1T as declared in the (sub)program from which F08RAF (DORCSD) is called.
Constraint: if ${\mathbf{JOBV1T}}=\text{'Y'}$, ${\mathbf{LDV1T}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{Q}}\right)$.
25:   $\mathrm{V2T}\left({\mathbf{LDV2T}},*\right)$ – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array V2T must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{Q}}\right)$ if ${\mathbf{JOBV2T}}=\text{'Y'}$, and at least $1$ otherwise.
On exit: if ${\mathbf{JOBV2T}}=\text{'Y'}$, V2T contains the $m-q$ by $m-q$ orthogonal matrix ${{V}_{2}}^{\mathrm{T}}$.
26:   $\mathrm{LDV2T}$ – INTEGERInput
On entry: the first dimension of the array V2T as declared in the (sub)program from which F08RAF (DORCSD) is called.
Constraint: if ${\mathbf{JOBV2T}}=\text{'Y'}$, ${\mathbf{LDV2T}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{Q}}\right)$.
27:   $\mathrm{WORK}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{LWORK}}\right)\right)$ – REAL (KIND=nag_wp) arrayWorkspace
On exit: if ${\mathbf{INFO}}={\mathbf{0}}$, ${\mathbf{WORK}}\left(1\right)$ returns the optimal LWORK.
If ${\mathbf{INFO}}>{\mathbf{0}}$ on exit, ${\mathbf{WORK}}\left(2:\mathit{r}\right)$ contains the values $\mathrm{PHI}\left(1\right),\dots \mathrm{PHI}\left(\mathit{r}-1\right)$ that, together with ${\mathrm{xref}}^{arg}\left(1\right),\dots {\mathrm{xref}}^{arg}\left(\mathit{r}\right)$, define the matrix in intermediate bidiagonal-block form remaining after nonconvergence. INFO specifies the number of nonzero PHI's.
28:   $\mathrm{LWORK}$ – INTEGERInput
On entry:
If ${\mathbf{LWORK}}=-1$, a workspace query is assumed; the routine only calculates the optimal size of the WORK array, returns this value as the first entry of the WORK array, and no error message related to LWORK is issued.
The minimum workspace required is $5×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,r-1\right)+4×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,r\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,8r\right)+\phantom{\rule{0ex}{0ex}}\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,p\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,m-p\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,q\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,m-q\right)+1$ where $r=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,m-p,q,m-q\right)$. The optimal workspace depends on internal block sizes and the relative dimensions of the problem.
Constraint: ${\mathbf{LWORK}}=-1$ or
${\mathbf{LWORK}}\ge 5×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,r-1\right)+4×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,r\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,8r\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{P}}\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{P}}\right)+\phantom{\rule{0ex}{0ex}}\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{Q}}\right)+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{M}}-{\mathbf{Q}}\right)+1$.
29:   $\mathrm{IWORK}\left({\mathbf{M}}-\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{P}},{\mathbf{M}}-{\mathbf{P}},{\mathbf{Q}},{\mathbf{M}}-{\mathbf{Q}}\right)\right)$ – INTEGER arrayWorkspace
30:   $\mathrm{INFO}$ – INTEGEROutput
On exit: ${\mathbf{INFO}}=0$ unless the routine detects an error (see Section 6).

## 6  Error Indicators and Warnings

${\mathbf{INFO}}<0$
If ${\mathbf{INFO}}=-i$, argument $i$ had an illegal value. An explanatory message is output, and execution of the program is terminated.
${\mathbf{INFO}}>0$
The Jacobi-type procedure failed to converge during an internal reduction to bidiagonal-block form. The process requires convergence to $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{P}},{\mathbf{M}}-{\mathbf{P}},{\mathbf{Q}},{\mathbf{M}}-{\mathbf{Q}}\right)$ values, the value of INFO gives the number of converged values.

## 7  Accuracy

The computed $CS$ decomposition is nearly the exact $CS$ decomposition for the nearby matrix $\left(X+E\right)$, where
 $E2 = Oε ,$
and $\epsilon$ is the machine precision.

## 8  Parallelism and Performance

F08RAF (DORCSD) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
F08RAF (DORCSD) 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.

The total number of floating-point operations required to perform the full $CS$ decomposition is approximately $2{m}^{3}$.
The complex analogue of this routine is F08RNF (ZUNCSD).

## 10  Example

This example finds the full CS decomposition of
 $X = -0.7576 0.3697 0.3838 0.2126 -0.3112 -0.4077 -0.1552 -0.1129 0.2676 0.8517 -0.0488 0.7240 -0.6730 -0.1301 0.0602 -0.2287 0.0088 0.2235 -0.9235 0.2120 0.4530 0.5612 0.5806 0.1162 0.3595$
partitioned so that the top left block is $3$ by $2$.
The decomposition is performed both on submatrices of the orthogonal matrix $X$ and on separated partition matrices. Code is also provided to perform a recombining check if required.

### 10.1  Program Text

Program Text (f08rafe.f90)

### 10.2  Program Data

Program Data (f08rafe.d)

### 10.3  Program Results

Program Results (f08rafe.r)