# NAG Library Routine Document

## 1Purpose

f08yef (dtgsja) computes the generalized singular value decomposition (GSVD) of two real upper trapezoidal matrices $A$ and $B$, where $A$ is an $m$ by $n$ matrix and $B$ is a $p$ by $n$ matrix.
$A$ and $B$ are assumed to be in the form returned by f08vef (dggsvp) or f08vgf (dggsvp3).

## 2Specification

Fortran Interface
 Subroutine f08yef ( jobu, jobv, jobq, m, p, n, k, l, a, lda, b, ldb, tola, tolb, beta, u, ldu, v, ldv, q, ldq, work, info)
 Integer, Intent (In) :: m, p, n, k, l, lda, ldb, ldu, ldv, ldq Integer, Intent (Out) :: ncycle, info Real (Kind=nag_wp), Intent (In) :: tola, tolb Real (Kind=nag_wp), Intent (Inout) :: a(lda,*), b(ldb,*), u(ldu,*), v(ldv,*), q(ldq,*) Real (Kind=nag_wp), Intent (Out) :: alpha(n), beta(n), work(2*n) Character (1), Intent (In) :: jobu, jobv, jobq
#include nagmk26.h
 void f08yef_ (const char *jobu, const char *jobv, const char *jobq, const Integer *m, const Integer *p, const Integer *n, const Integer *k, const Integer *l, double a[], const Integer *lda, double b[], const Integer *ldb, const double *tola, const double *tolb, double alpha[], double beta[], double u[], const Integer *ldu, double v[], const Integer *ldv, double q[], const Integer *ldq, double work[], Integer *ncycle, Integer *info, const Charlen length_jobu, const Charlen length_jobv, const Charlen length_jobq)
The routine may be called by its LAPACK name dtgsja.

## 3Description

f08yef (dtgsja) computes the GSVD of the matrices $A$ and $B$ which are assumed to have the form as returned by f08vef (dggsvp) or f08vgf (dggsvp3)
 $A= n-k-lklk0A12A13l00A23m-k-l000() , if ​ m-k-l ≥ 0; n-k-lklk0A12A13m-k00A23() , if ​ m-k-l < 0 ; B= n-k-lkll00B13p-l000() ,$
where the $k$ by $k$ matrix ${A}_{12}$ and the $l$ by $l$ matrix ${B}_{13}$ are nonsingular upper triangular, ${A}_{23}$ is $l$ by $l$ upper triangular if $m-k-l\ge 0$ and is $\left(m-k\right)$ by $l$ upper trapezoidal otherwise.
f08yef (dtgsja) computes orthogonal matrices $Q$, $U$ and $V$, diagonal matrices ${D}_{1}$ and ${D}_{2}$, and an upper triangular matrix $R$ such that
 $UTAQ = D1 0 R , VTBQ = D2 0 R .$
Optionally $Q$, $U$ and $V$ may or may not be computed, or they may be premultiplied by matrices ${Q}_{1}$, ${U}_{1}$ and ${V}_{1}$ respectively.
If $\left(m-k-l\right)\ge 0$ then ${D}_{1}$, ${D}_{2}$ and $R$ have the form
 $D1= klkI0l0Cm-k-l00() ,$
 $D2= kll0Sp-l00() ,$
 $R = klkR11R12l0R22() ,$
where $C=\mathrm{diag}\left({\alpha }_{k+1},,,\dots ,,,{\alpha }_{k+l}\right)\text{, }S=\mathrm{diag}\left({\beta }_{k+1},,,\dots ,,,{\beta }_{k+l}\right)$.
If $\left(m-k-l\right)<0$ then ${D}_{1}$, ${D}_{2}$ and $R$ have the form
 $D1= km-kk+l-mkI00m-k0C0() ,$
 $D2= km-kk+l-mm-k0S0k+l-m00Ip-l000() ,$
 $R = km-kk+l-mkR11R12R13m-k0R22R23k+l-m00R33() ,$
where $C=\mathrm{diag}\left({\alpha }_{k+1},,,\dots ,,,{\alpha }_{m}\right)\text{, }S=\mathrm{diag}\left({\beta }_{k+1},,,\dots ,,,{\beta }_{m}\right)$.
In both cases the diagonal matrix $C$ has non-negative diagonal elements, the diagonal matrix $S$ has positive diagonal elements, so that $S$ is nonsingular, and ${C}^{2}+{S}^{2}=1$. See Section 2.3.5.3 of Anderson et al. (1999) for further information.
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 (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5Arguments

1:     $\mathbf{jobu}$ – Character(1)Input
On entry: if ${\mathbf{jobu}}=\text{'U'}$, u must contain an orthogonal matrix ${U}_{1}$ on entry, and the product ${U}_{1}U$ is returned.
If ${\mathbf{jobu}}=\text{'I'}$, u is initialized to the unit matrix, and the orthogonal matrix $U$ is returned.
If ${\mathbf{jobu}}=\text{'N'}$, $U$ is not computed.
Constraint: ${\mathbf{jobu}}=\text{'U'}$, $\text{'I'}$ or $\text{'N'}$.
2:     $\mathbf{jobv}$ – Character(1)Input
On entry: if ${\mathbf{jobv}}=\text{'V'}$, v must contain an orthogonal matrix ${V}_{1}$ on entry, and the product ${V}_{1}V$ is returned.
If ${\mathbf{jobv}}=\text{'I'}$, v is initialized to the unit matrix, and the orthogonal matrix $V$ is returned.
If ${\mathbf{jobv}}=\text{'N'}$, $V$ is not computed.
Constraint: ${\mathbf{jobv}}=\text{'V'}$, $\text{'I'}$ or $\text{'N'}$.
3:     $\mathbf{jobq}$ – Character(1)Input
On entry: if ${\mathbf{jobq}}=\text{'Q'}$, q must contain an orthogonal matrix ${Q}_{1}$ on entry, and the product ${Q}_{1}Q$ is returned.
If ${\mathbf{jobq}}=\text{'I'}$, q is initialized to the unit matrix, and the orthogonal matrix $Q$ is returned.
If ${\mathbf{jobq}}=\text{'N'}$, $Q$ is not computed.
Constraint: ${\mathbf{jobq}}=\text{'Q'}$, $\text{'I'}$ or $\text{'N'}$.
4:     $\mathbf{m}$ – IntegerInput
On entry: $m$, the number of rows of the matrix $A$.
Constraint: ${\mathbf{m}}\ge 0$.
5:     $\mathbf{p}$ – IntegerInput
On entry: $p$, the number of rows of the matrix $B$.
Constraint: ${\mathbf{p}}\ge 0$.
6:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the number of columns of the matrices $A$ and $B$.
Constraint: ${\mathbf{n}}\ge 0$.
7:     $\mathbf{k}$ – IntegerInput
8:     $\mathbf{l}$ – IntegerInput
On entry: k and l specify the sizes, $k$ and $l$, of the subblocks of $A$ and $B$, whose GSVD is to be computed by f08yef (dtgsja).
9:     $\mathbf{a}\left({\mathbf{lda}},*\right)$ – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the $m$ by $n$ matrix $A$.
On exit: if $m-k-l\ge 0$, ${\mathbf{a}}\left(1:k+l,n-k-l+1:n\right)$ contains the $\left(k+l\right)$ by $\left(k+l\right)$ upper triangular matrix $R$.
If $m-k-l<0$, ${\mathbf{a}}\left(1:m,n-k-l+1:n\right)$ contains the first $m$ rows of the $\left(k+l\right)$ by $\left(k+l\right)$ upper triangular matrix $R$, and the submatrix ${R}_{33}$ is returned in ${\mathbf{b}}\left(m-k+1:l,n+m-k-l+1:n\right)$.
10:   $\mathbf{lda}$ – IntegerInput
On entry: the first dimension of the array a as declared in the (sub)program from which f08yef (dtgsja) is called.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
11:   $\mathbf{b}\left({\mathbf{ldb}},*\right)$ – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array b must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the $p$ by $n$ matrix $B$.
On exit: if $m-k-l<0$, ${\mathbf{b}}\left(m-k+1:l,n+m-k-l+1:n\right)$ contains the submatrix ${R}_{33}$ of $R$.
12:   $\mathbf{ldb}$ – IntegerInput
On entry: the first dimension of the array b as declared in the (sub)program from which f08yef (dtgsja) is called.
Constraint: ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{p}}\right)$.
13:   $\mathbf{tola}$ – Real (Kind=nag_wp)Input
14:   $\mathbf{tolb}$ – Real (Kind=nag_wp)Input
On entry: tola and tolb are the convergence criteria for the Jacobi–Kogbetliantz iteration procedure. Generally, they should be the same as used in the preprocessing step performed by f08vef (dggsvp) or f08vgf (dggsvp3), say
 $tola=maxm,nAε, tolb=maxp,nBε,$
where $\epsilon$ is the machine precision.
15:   $\mathbf{alpha}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: see the description of beta.
16:   $\mathbf{beta}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: alpha and beta contain the generalized singular value pairs of $A$ and $B$;
• ${\mathbf{alpha}}\left(\mathit{i}\right)=1$, ${\mathbf{beta}}\left(\mathit{i}\right)=0$, for $\mathit{i}=1,2,\dots ,k$, and
• if $m-k-l\ge 0$, ${\mathbf{alpha}}\left(\mathit{i}\right)={\alpha }_{\mathit{i}}$, ${\mathbf{beta}}\left(\mathit{i}\right)={\beta }_{\mathit{i}}$, for $\mathit{i}=k+1,\dots ,k+l$, or
• if $m-k-l<0$, ${\mathbf{alpha}}\left(\mathit{i}\right)={\alpha }_{\mathit{i}}$, ${\mathbf{beta}}\left(\mathit{i}\right)={\beta }_{\mathit{i}}$, for $\mathit{i}=k+1,\dots ,m$ and ${\mathbf{alpha}}\left(\mathit{i}\right)=0$, ${\mathbf{beta}}\left(\mathit{i}\right)=1$, for $\mathit{i}=m+1,\dots ,k+l$.
Furthermore, if $k+l, ${\mathbf{alpha}}\left(\mathit{i}\right)={\mathbf{beta}}\left(\mathit{i}\right)=0$, for $\mathit{i}=k+l+1,\dots ,n$.
17:   $\mathbf{u}\left({\mathbf{ldu}},*\right)$ – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array u must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$ if ${\mathbf{jobu}}=\text{'U'}$ or $\text{'I'}$, and at least $1$ otherwise.
On entry: if ${\mathbf{jobu}}=\text{'U'}$, u must contain an $m$ by $m$ matrix ${U}_{1}$ (usually the orthogonal matrix returned by f08vef (dggsvp) or f08vgf (dggsvp3)).
On exit: if ${\mathbf{jobu}}=\text{'U'}$, u contains the product ${U}_{1}U$.
If ${\mathbf{jobu}}=\text{'I'}$, u contains the orthogonal matrix $U$.
If ${\mathbf{jobu}}=\text{'N'}$, u is not referenced.
18:   $\mathbf{ldu}$ – IntegerInput
On entry: the first dimension of the array u as declared in the (sub)program from which f08yef (dtgsja) is called.
Constraints:
• if ${\mathbf{jobu}}=\text{'U'}$ or $\text{'I'}$, ${\mathbf{ldu}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• otherwise ${\mathbf{ldu}}\ge 1$.
19:   $\mathbf{v}\left({\mathbf{ldv}},*\right)$ – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array v must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{p}}\right)$ if ${\mathbf{jobv}}=\text{'V'}$ or $\text{'I'}$, and at least $1$ otherwise.
On entry: if ${\mathbf{jobv}}=\text{'V'}$, v must contain an $p$ by $p$ matrix ${V}_{1}$ (usually the orthogonal matrix returned by f08vef (dggsvp) or f08vgf (dggsvp3)).
On exit: if ${\mathbf{jobv}}=\text{'I'}$, v contains the orthogonal matrix $V$.
If ${\mathbf{jobv}}=\text{'V'}$, v contains the product ${V}_{1}V$.
If ${\mathbf{jobv}}=\text{'N'}$, v is not referenced.
20:   $\mathbf{ldv}$ – IntegerInput
On entry: the first dimension of the array v as declared in the (sub)program from which f08yef (dtgsja) is called.
Constraints:
• if ${\mathbf{jobv}}=\text{'V'}$ or $\text{'I'}$, ${\mathbf{ldv}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{p}}\right)$;
• otherwise ${\mathbf{ldv}}\ge 1$.
21:   $\mathbf{q}\left({\mathbf{ldq}},*\right)$ – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array q must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{jobq}}=\text{'Q'}$ or $\text{'I'}$, and at least $1$ otherwise.
On entry: if ${\mathbf{jobq}}=\text{'Q'}$, q must contain an $n$ by $n$ matrix ${Q}_{1}$ (usually the orthogonal matrix returned by f08vef (dggsvp) or f08vgf (dggsvp3)).
On exit: if ${\mathbf{jobq}}=\text{'I'}$, q contains the orthogonal matrix $Q$.
If ${\mathbf{jobq}}=\text{'Q'}$, q contains the product ${Q}_{1}Q$.
If ${\mathbf{jobq}}=\text{'N'}$, q is not referenced.
22:   $\mathbf{ldq}$ – IntegerInput
On entry: the first dimension of the array q as declared in the (sub)program from which f08yef (dtgsja) is called.
Constraints:
• if ${\mathbf{jobq}}=\text{'Q'}$ or $\text{'I'}$, ${\mathbf{ldq}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ${\mathbf{ldq}}\ge 1$.
23:   $\mathbf{work}\left(2×{\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
24:   $\mathbf{ncycle}$ – IntegerOutput
On exit: the number of cycles required for convergence.
25:   $\mathbf{info}$ – IntegerOutput
On exit: ${\mathbf{info}}=0$ unless the routine detects an error (see Section 6).

## 6Error 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}}=1$
The procedure does not converge after $40$ cycles.

## 7Accuracy

The computed generalized singular value decomposition is nearly the exact generalized singular value decomposition for nearby matrices $\left(A+E\right)$ and $\left(B+F\right)$, where
 $E2 = O⁡ε A2 and F2= O⁡ε B2 ,$
and $\epsilon$ is the machine precision. See Section 4.12 of Anderson et al. (1999) for further details.

## 8Parallelism and Performance

f08yef (dtgsja) 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 complex analogue of this routine is f08ysf (ztgsja).

## 10Example

This example finds the generalized singular value decomposition
 $A = UΣ1 0 R QT , B= VΣ2 0 R QT ,$
of the matrix pair $\left(A,B\right)$, where
 $A = 1 2 3 3 2 1 4 5 6 7 8 8 and B= -2 -3 3 4 6 5 .$

### 10.1Program Text

Program Text (f08yefe.f90)

### 10.2Program Data

Program Data (f08yefe.d)

### 10.3Program Results

Program Results (f08yefe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017