# NAG Library Routine Document

## 1Purpose

f08ykf (dtgevc) computes some or all of the right and/or left generalized eigenvectors of a pair of real matrices $\left(A,B\right)$ which are in generalized real Schur form.

## 2Specification

Fortran Interface
 Subroutine f08ykf ( side, n, a, lda, b, ldb, vl, ldvl, vr, ldvr, mm, m, work, info)
 Integer, Intent (In) :: n, lda, ldb, ldvl, ldvr, mm Integer, Intent (Out) :: m, info Real (Kind=nag_wp), Intent (In) :: a(lda,*), b(ldb,*) Real (Kind=nag_wp), Intent (Inout) :: vl(ldvl,*), vr(ldvr,*) Real (Kind=nag_wp), Intent (Out) :: work(6*n) Logical, Intent (In) :: select(*) Character (1), Intent (In) :: side, howmny
#include nagmk26.h
 void f08ykf_ (const char *side, const char *howmny, const logical sel[], const Integer *n, const double a[], const Integer *lda, const double b[], const Integer *ldb, double vl[], const Integer *ldvl, double vr[], const Integer *ldvr, const Integer *mm, Integer *m, double work[], Integer *info, const Charlen length_side, const Charlen length_howmny)
The routine may be called by its LAPACK name dtgevc.

## 3Description

f08ykf (dtgevc) computes some or all of the right and/or left generalized eigenvectors of the matrix pair $\left(A,B\right)$ which is assumed to be in generalized upper Schur form. If the matrix pair $\left(A,B\right)$ is not in the generalized upper Schur form, then f08xef (dhgeqz) should be called before invoking f08ykf (dtgevc).
The right generalized eigenvector $x$ and the left generalized eigenvector $y$ of $\left(A,B\right)$ corresponding to a generalized eigenvalue $\lambda$ are defined by
 $A-λBx=0$
and
 $yH A-λ B=0.$
If a generalized eigenvalue is determined as $0/0$, which is due to zero diagonal elements at the same locations in both $A$ and $B$, a unit vector is returned as the corresponding eigenvector.
Note that the generalized eigenvalues are computed using f08xef (dhgeqz) but f08ykf (dtgevc) does not explicitly require the generalized eigenvalues to compute eigenvectors. The ordering of the eigenvectors is based on the ordering of the eigenvalues as computed by f08ykf (dtgevc).
If all eigenvectors are requested, the routine may either return the matrices $X$ and/or $Y$ of right or left eigenvectors of $\left(A,B\right)$, or the products $ZX$ and/or $QY$, where $Z$ and $Q$ are two matrices supplied by you. Usually, $Q$ and $Z$ are chosen as the orthogonal matrices returned by f08xef (dhgeqz). Equivalently, $Q$ and $Z$ are the left and right Schur vectors of the matrix pair supplied to f08xef (dhgeqz). In that case, $QY$ and $ZX$ are the left and right generalized eigenvectors, respectively, of the matrix pair supplied to f08xef (dhgeqz).
$A$ must be block upper triangular; with $1$ by $1$ and $2$ by $2$ diagonal blocks. Corresponding to each $2$ by $2$ diagonal block is a complex conjugate pair of eigenvalues and eigenvectors; only one eigenvector of the pair is computed, namely the one corresponding to the eigenvalue with positive imaginary part. Each $1$ by $1$ block gives a real generalized eigenvalue and a corresponding eigenvector.

## 4References

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
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Moler C B and Stewart G W (1973) An algorithm for generalized matrix eigenproblems SIAM J. Numer. Anal. 10 241–256
Stewart G W and Sun J-G (1990) Matrix Perturbation Theory Academic Press, London

## 5Arguments

1:     $\mathbf{side}$ – Character(1)Input
On entry: specifies the required sets of generalized eigenvectors.
${\mathbf{side}}=\text{'R'}$
Only right eigenvectors are computed.
${\mathbf{side}}=\text{'L'}$
Only left eigenvectors are computed.
${\mathbf{side}}=\text{'B'}$
Both left and right eigenvectors are computed.
Constraint: ${\mathbf{side}}=\text{'B'}$, $\text{'L'}$ or $\text{'R'}$.
2:     $\mathbf{howmny}$ – Character(1)Input
On entry: specifies further details of the required generalized eigenvectors.
${\mathbf{howmny}}=\text{'A'}$
All right and/or left eigenvectors are computed.
${\mathbf{howmny}}=\text{'B'}$
All right and/or left eigenvectors are computed; they are backtransformed using the input matrices supplied in arrays vr and/or vl.
${\mathbf{howmny}}=\text{'S'}$
Selected right and/or left eigenvectors, defined by the array select, are computed.
Constraint: ${\mathbf{howmny}}=\text{'A'}$, $\text{'B'}$ or $\text{'S'}$.
3:     $\mathbf{select}\left(*\right)$ – Logical arrayInput
Note: the dimension of the array select must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{howmny}}=\text{'S'}$, and at least $1$ otherwise.
On entry: specifies the eigenvectors to be computed if ${\mathbf{howmny}}=\text{'S'}$. To select the generalized eigenvector corresponding to the $j$th generalized eigenvalue, the $j$th element of select should be set to .TRUE.; if the eigenvalue corresponds to a complex conjugate pair, then real and imaginary parts of eigenvectors corresponding to the complex conjugate eigenvalue pair will be computed.
If ${\mathbf{howmny}}=\text{'A'}$ or $\text{'B'}$, select is not referenced.
Constraint: if ${\mathbf{howmny}}=\text{'S'}$, ${\mathbf{select}}\left(\mathit{j}\right)=\mathrm{.TRUE.}$ or $\mathrm{.FALSE.}$, for $\mathit{j}=1,2,\dots ,n$.
4:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the order of the matrices $A$ and $B$.
Constraint: ${\mathbf{n}}\ge 0$.
5:     $\mathbf{a}\left({\mathbf{lda}},*\right)$ – Real (Kind=nag_wp) arrayInput
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 matrix pair $\left(A,B\right)$ must be in the generalized Schur form. Usually, this is the matrix $A$ returned by f08xef (dhgeqz).
6:     $\mathbf{lda}$ – IntegerInput
On entry: the first dimension of the array a as declared in the (sub)program from which f08ykf (dtgevc) is called.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
7:     $\mathbf{b}\left({\mathbf{ldb}},*\right)$ – Real (Kind=nag_wp) arrayInput
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 matrix pair $\left(A,B\right)$ must be in the generalized Schur form. If $A$ has a $2$ by $2$ diagonal block then the corresponding $2$ by $2$ block of $B$ must be diagonal with positive elements. Usually, this is the matrix $B$ returned by f08xef (dhgeqz).
8:     $\mathbf{ldb}$ – IntegerInput
On entry: the first dimension of the array b as declared in the (sub)program from which f08ykf (dtgevc) is called.
Constraint: ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
9:     $\mathbf{vl}\left({\mathbf{ldvl}},*\right)$ – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array vl must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if ${\mathbf{side}}=\text{'L'}$ or $\text{'B'}$ and at least $1$ if ${\mathbf{side}}=\text{'R'}$.
On entry: if ${\mathbf{howmny}}=\text{'B'}$ and ${\mathbf{side}}=\text{'L'}$ or $\text{'B'}$, vl must be initialized to an $n$ by $n$ matrix $Q$. Usually, this is the orthogonal matrix $Q$ of left Schur vectors returned by f08xef (dhgeqz).
On exit: if ${\mathbf{side}}=\text{'L'}$ or $\text{'B'}$, vl contains:
• if ${\mathbf{howmny}}=\text{'A'}$, the matrix $Y$ of left eigenvectors of $\left(A,B\right)$;
• if ${\mathbf{howmny}}=\text{'B'}$, the matrix $QY$;
• if ${\mathbf{howmny}}=\text{'S'}$, the left eigenvectors of $\left(A,B\right)$ specified by select, stored consecutively in the columns of the array vl, in the same order as their corresponding eigenvalues.
A complex eigenvector corresponding to a complex eigenvalue is stored in two consecutive columns, the first holding the real part, and the second the imaginary part.
If ${\mathbf{side}}=\text{'R'}$, vl is not referenced.
10:   $\mathbf{ldvl}$ – IntegerInput
On entry: the first dimension of the array vl as declared in the (sub)program from which f08ykf (dtgevc) is called.
Constraints:
• if ${\mathbf{side}}=\text{'L'}$ or $\text{'B'}$, ${\mathbf{ldvl}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{side}}=\text{'R'}$, ${\mathbf{ldvl}}\ge 1$.
11:   $\mathbf{vr}\left({\mathbf{ldvr}},*\right)$ – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array vr must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if ${\mathbf{side}}=\text{'R'}$ or $\text{'B'}$ and at least $1$ if ${\mathbf{side}}=\text{'L'}$.
On entry: if ${\mathbf{howmny}}=\text{'B'}$ and ${\mathbf{side}}=\text{'R'}$ or $\text{'B'}$, vr must be initialized to an $n$ by $n$ matrix $Z$. Usually, this is the orthogonal matrix $Z$ of right Schur vectors returned by f08xef (dhgeqz).
On exit: if ${\mathbf{side}}=\text{'R'}$ or $\text{'B'}$, vr contains:
• if ${\mathbf{howmny}}=\text{'A'}$, the matrix $X$ of right eigenvectors of $\left(A,B\right)$;
• if ${\mathbf{howmny}}=\text{'B'}$, the matrix $ZX$;
• if ${\mathbf{howmny}}=\text{'S'}$, the right eigenvectors of $\left(A,B\right)$ specified by select, stored consecutively in the columns of the array vr, in the same order as their corresponding eigenvalues.
A complex eigenvector corresponding to a complex eigenvalue is stored in two consecutive columns, the first holding the real part, and the second the imaginary part.
If ${\mathbf{side}}=\text{'L'}$, vr is not referenced.
12:   $\mathbf{ldvr}$ – IntegerInput
On entry: the first dimension of the array vr as declared in the (sub)program from which f08ykf (dtgevc) is called.
Constraints:
• if ${\mathbf{side}}=\text{'R'}$ or $\text{'B'}$, ${\mathbf{ldvr}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{side}}=\text{'L'}$, ${\mathbf{ldvr}}\ge 1$.
13:   $\mathbf{mm}$ – IntegerInput
On entry: the number of columns in the arrays vl and/or vr.
Constraints:
• if ${\mathbf{howmny}}=\text{'A'}$ or $\text{'B'}$, ${\mathbf{mm}}\ge {\mathbf{n}}$;
• if ${\mathbf{howmny}}=\text{'S'}$, mm must not be less than the number of requested eigenvectors.
14:   $\mathbf{m}$ – IntegerOutput
On exit: the number of columns in the arrays vl and/or vr actually used to store the eigenvectors. If ${\mathbf{howmny}}=\text{'A'}$ or $\text{'B'}$, m is set to n. Each selected real eigenvector occupies one column and each selected complex eigenvector occupies two columns.
15:   $\mathbf{work}\left(6×{\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
16:   $\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}}>0$
If ${\mathbf{info}}=i$, the $2$ by $2$ block $\left({\mathbf{info}}:{\mathbf{info}}+1\right)$ does not have complex eigenvalues.

## 7Accuracy

It is beyond the scope of this manual to summarise the accuracy of the solution of the generalized eigenvalue problem. Interested readers should consult Section 4.11 of the LAPACK Users' Guide (see Anderson et al. (1999)) and Chapter 6 of Stewart and Sun (1990).

## 8Parallelism and Performance

f08ykf (dtgevc) 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.

f08ykf (dtgevc) is the sixth step in the solution of the real generalized eigenvalue problem and is called after f08xef (dhgeqz).
The complex analogue of this routine is f08yxf (ztgevc).

## 10Example

This example computes the $\alpha$ and $\beta$ arguments, which defines the generalized eigenvalues and the corresponding left and right eigenvectors, of the matrix pair $\left(A,B\right)$ given by
 $A = 1.0 1.0 1.0 1.0 1.0 2.0 4.0 8.0 16.0 32.0 3.0 9.0 27.0 81.0 243.0 4.0 16.0 64.0 256.0 1024.0 5.0 25.0 125.0 625.0 3125.0 and B= 1.0 2.0 3.0 4.0 5.0 1.0 4.0 9.0 16.0 25.0 1.0 8.0 27.0 64.0 125.0 1.0 16.0 81.0 256.0 625.0 1.0 32.0 243.0 1024.0 3125.0 .$
To compute generalized eigenvalues, it is required to call five routines: f08whf (dggbal) to balance the matrix, f08aef (dgeqrf) to perform the $QR$ factorization of $B$, f08agf (dormqr) to apply $Q$ to $A$, f08wef (dgghrd) to reduce the matrix pair to the generalized Hessenberg form and f08xef (dhgeqz) to compute the eigenvalues via the $QZ$ algorithm.
The computation of generalized eigenvectors is done by calling f08ykf (dtgevc) to compute the eigenvectors of the balanced matrix pair. The routine f08wjf (dggbak) is called to backward transform the eigenvectors to the user-supplied matrix pair. If both left and right eigenvectors are required then f08wjf (dggbak) must be called twice.

### 10.1Program Text

Program Text (f08ykfe.f90)

### 10.2Program Data

Program Data (f08ykfe.d)

### 10.3Program Results

Program Results (f08ykfe.r)

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