# NAG Library Function Document

## 1Purpose

nag_dtgevc (f08ykc) 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

 #include #include
 void nag_dtgevc (Nag_OrderType order, Nag_SideType side, Nag_HowManyType how_many, const Nag_Boolean select[], Integer n, const double a[], Integer pda, const double b[], Integer pdb, double vl[], Integer pdvl, double vr[], Integer pdvr, Integer mm, Integer *m, NagError *fail)

## 3Description

nag_dtgevc (f08ykc) 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 nag_dhgeqz (f08xec) should be called before invoking nag_dtgevc (f08ykc).
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 nag_dhgeqz (f08xec) but nag_dtgevc (f08ykc) 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 nag_dtgevc (f08ykc).
If all eigenvectors are requested, the function 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 nag_dhgeqz (f08xec). Equivalently, $Q$ and $Z$ are the left and right Schur vectors of the matrix pair supplied to nag_dhgeqz (f08xec). In that case, $QY$ and $ZX$ are the left and right generalized eigenvectors, respectively, of the matrix pair supplied to nag_dhgeqz (f08xec).
$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{order}$Nag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.3.1.3 in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2:    $\mathbf{side}$Nag_SideTypeInput
On entry: specifies the required sets of generalized eigenvectors.
${\mathbf{side}}=\mathrm{Nag_RightSide}$
Only right eigenvectors are computed.
${\mathbf{side}}=\mathrm{Nag_LeftSide}$
Only left eigenvectors are computed.
${\mathbf{side}}=\mathrm{Nag_BothSides}$
Both left and right eigenvectors are computed.
Constraint: ${\mathbf{side}}=\mathrm{Nag_BothSides}$, $\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_RightSide}$.
3:    $\mathbf{how_many}$Nag_HowManyTypeInput
On entry: specifies further details of the required generalized eigenvectors.
${\mathbf{how_many}}=\mathrm{Nag_ComputeAll}$
All right and/or left eigenvectors are computed.
${\mathbf{how_many}}=\mathrm{Nag_BackTransform}$
All right and/or left eigenvectors are computed; they are backtransformed using the input matrices supplied in arrays vr and/or vl.
${\mathbf{how_many}}=\mathrm{Nag_ComputeSelected}$
Selected right and/or left eigenvectors, defined by the array select, are computed.
Constraint: ${\mathbf{how_many}}=\mathrm{Nag_ComputeAll}$, $\mathrm{Nag_BackTransform}$ or $\mathrm{Nag_ComputeSelected}$.
4:    $\mathbf{select}\left[\mathit{dim}\right]$const Nag_BooleanInput
Note: the dimension, dim, of the array select must be at least
• ${\mathbf{n}}$ when ${\mathbf{how_many}}=\mathrm{Nag_ComputeSelected}$;
• otherwise select may be NULL.
On entry: specifies the eigenvectors to be computed if ${\mathbf{how_many}}=\mathrm{Nag_ComputeSelected}$. To select the generalized eigenvector corresponding to the $j$th generalized eigenvalue, the $j$th element of select should be set to Nag_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{how_many}}=\mathrm{Nag_ComputeAll}$ or $\mathrm{Nag_BackTransform}$, select is not referenced and may be NULL.
Constraint: if ${\mathbf{how_many}}=\mathrm{Nag_ComputeSelected}$, ${\mathbf{select}}\left[\mathit{j}\right]=\mathrm{Nag_TRUE}$ or $\mathrm{Nag_FALSE}$, for $\mathit{j}=0,1,\dots ,n-1$.
5:    $\mathbf{n}$IntegerInput
On entry: $n$, the order of the matrices $A$ and $B$.
Constraint: ${\mathbf{n}}\ge 0$.
6:    $\mathbf{a}\left[\mathit{dim}\right]$const doubleInput
Note: the dimension, dim, of the array a must be at least ${\mathbf{pda}}×{\mathbf{n}}$.
The $\left(i,j\right)$th element of the matrix $A$ is stored in
• ${\mathbf{a}}\left[\left(j-1\right)×{\mathbf{pda}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{a}}\left[\left(i-1\right)×{\mathbf{pda}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: the matrix pair $\left(A,B\right)$ must be in the generalized Schur form. Usually, this is the matrix $A$ returned by nag_dhgeqz (f08xec).
7:    $\mathbf{pda}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array a.
Constraint: ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
8:    $\mathbf{b}\left[\mathit{dim}\right]$const doubleInput
Note: the dimension, dim, of the array b must be at least ${\mathbf{pdb}}×{\mathbf{n}}$.
The $\left(i,j\right)$th element of the matrix $B$ is stored in
• ${\mathbf{b}}\left[\left(j-1\right)×{\mathbf{pdb}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{b}}\left[\left(i-1\right)×{\mathbf{pdb}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
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 nag_dhgeqz (f08xec).
9:    $\mathbf{pdb}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array b.
Constraint: ${\mathbf{pdb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
10:  $\mathbf{vl}\left[\mathit{dim}\right]$doubleInput/Output
Note: the dimension, dim, of the array vl must be at least
• ${\mathbf{pdvl}}×{\mathbf{mm}}$ when ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$ and ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{n}}×{\mathbf{pdvl}}$ when ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$ and ${\mathbf{order}}=\mathrm{Nag_RowMajor}$;
• otherwise vl may be NULL.
The $\left(i,j\right)$th element of the matrix is stored in
• ${\mathbf{vl}}\left[\left(j-1\right)×{\mathbf{pdvl}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{vl}}\left[\left(i-1\right)×{\mathbf{pdvl}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: if ${\mathbf{how_many}}=\mathrm{Nag_BackTransform}$ and ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, vl must be initialized to an $n$ by $n$ matrix $Q$. Usually, this is the orthogonal matrix $Q$ of left Schur vectors returned by nag_dhgeqz (f08xec).
On exit: if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, vl contains:
• if ${\mathbf{how_many}}=\mathrm{Nag_ComputeAll}$, the matrix $Y$ of left eigenvectors of $\left(A,B\right)$;
• if ${\mathbf{how_many}}=\mathrm{Nag_BackTransform}$, the matrix $QY$;
• if ${\mathbf{how_many}}=\mathrm{Nag_ComputeSelected}$, the left eigenvectors of $\left(A,B\right)$ specified by select, stored consecutively in the rows or columns (depending on the value of order) 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 rows or columns, the first holding the real part, and the second the imaginary part.
If ${\mathbf{side}}=\mathrm{Nag_RightSide}$, vl is not referenced and may be NULL.
11:  $\mathbf{pdvl}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array vl.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$,
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvl}}\ge {\mathbf{n}}$;
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, vl may be NULL;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$,
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvl}}\ge {\mathbf{mm}}$;
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$, vl may be NULL.
12:  $\mathbf{vr}\left[\mathit{dim}\right]$doubleInput/Output
Note: the dimension, dim, of the array vr must be at least
• ${\mathbf{pdvr}}×{\mathbf{mm}}$ when ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$ and ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{n}}×{\mathbf{pdvr}}$ when ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$ and ${\mathbf{order}}=\mathrm{Nag_RowMajor}$;
• otherwise vr may be NULL.
The $\left(i,j\right)$th element of the matrix is stored in
• ${\mathbf{vr}}\left[\left(j-1\right)×{\mathbf{pdvr}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{vr}}\left[\left(i-1\right)×{\mathbf{pdvr}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: if ${\mathbf{how_many}}=\mathrm{Nag_BackTransform}$ and ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, vr must be initialized to an $n$ by $n$ matrix $Z$. Usually, this is the orthogonal matrix $Z$ of right Schur vectors returned by nag_dhgeqz (f08xec).
On exit: if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, vr contains:
• if ${\mathbf{how_many}}=\mathrm{Nag_ComputeAll}$, the matrix $X$ of right eigenvectors of $\left(A,B\right)$;
• if ${\mathbf{how_many}}=\mathrm{Nag_BackTransform}$, the matrix $ZX$;
• if ${\mathbf{how_many}}=\mathrm{Nag_ComputeSelected}$, the right eigenvectors of $\left(A,B\right)$ specified by select, stored consecutively in the rows or columns (depending on the value of order) 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 rows or columns, the first holding the real part, and the second the imaginary part.
If ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, vr is not referenced and may be NULL.
13:  $\mathbf{pdvr}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array vr.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$,
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvr}}\ge {\mathbf{n}}$;
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, vr may be NULL;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$,
• if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvr}}\ge {\mathbf{mm}}$;
• if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$, vr may be NULL.
14:  $\mathbf{mm}$IntegerInput
On entry: the number of columns in the arrays vl and/or vr.
Constraints:
• if ${\mathbf{how_many}}=\mathrm{Nag_ComputeAll}$ or $\mathrm{Nag_BackTransform}$, ${\mathbf{mm}}\ge {\mathbf{n}}$;
• if ${\mathbf{how_many}}=\mathrm{Nag_ComputeSelected}$, mm must not be less than the number of requested eigenvectors.
15:  $\mathbf{m}$Integer *Output
On exit: the number of columns in the arrays vl and/or vr actually used to store the eigenvectors. If ${\mathbf{how_many}}=\mathrm{Nag_ComputeAll}$ or $\mathrm{Nag_BackTransform}$, m is set to n. Each selected real eigenvector occupies one row or column and each selected complex eigenvector occupies two rows or columns.
16:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_CONSTRAINT
On entry, ${\mathbf{how_many}}=〈\mathit{\text{value}}〉$ and ${\mathbf{select}}\left[\mathit{j}\right]=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{how_many}}=\mathrm{Nag_ComputeSelected}$, ${\mathbf{select}}\left[\mathit{j}\right]=\mathrm{Nag_TRUE}$ or $\mathrm{Nag_FALSE}$, for $\mathit{j}=0,1,\dots ,n-1$.
NE_ENUM_INT_2
On entry, ${\mathbf{how_many}}=〈\mathit{\text{value}}〉$, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ and ${\mathbf{mm}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{how_many}}=\mathrm{Nag_ComputeAll}$ or $\mathrm{Nag_BackTransform}$, ${\mathbf{mm}}\ge {\mathbf{n}}$;
if ${\mathbf{how_many}}=\mathrm{Nag_ComputeSelected}$, mm must not be less than the number of requested eigenvectors.
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdvl}}=〈\mathit{\text{value}}〉$, ${\mathbf{mm}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvl}}\ge {\mathbf{mm}}$.
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdvl}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_LeftSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvl}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdvr}}=〈\mathit{\text{value}}〉$, ${\mathbf{mm}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvr}}\ge {\mathbf{mm}}$.
On entry, ${\mathbf{side}}=〈\mathit{\text{value}}〉$, ${\mathbf{pdvr}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{side}}=\mathrm{Nag_RightSide}$ or $\mathrm{Nag_BothSides}$, ${\mathbf{pdvr}}\ge {\mathbf{n}}$.
NE_INT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, ${\mathbf{pda}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pda}}>0$.
On entry, ${\mathbf{pdb}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdb}}>0$.
On entry, ${\mathbf{pdvl}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdvl}}>0$.
On entry, ${\mathbf{pdvr}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdvr}}>0$.
NE_INT_2
On entry, ${\mathbf{pda}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry, ${\mathbf{pdb}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_NOT_COMPLEX
The $2$ by $2$ block $\left(〈\mathit{\text{value}}〉:〈\mathit{\text{value}}〉+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

nag_dtgevc (f08ykc) 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

nag_dtgevc (f08ykc) is the sixth step in the solution of the real generalized eigenvalue problem and is called after nag_dhgeqz (f08xec).
The complex analogue of this function is nag_ztgevc (f08yxc).

## 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 functions: nag_dggbal (f08whc) to balance the matrix, nag_dgeqrf (f08aec) to perform the $QR$ factorization of $B$, nag_dormqr (f08agc) to apply $Q$ to $A$, nag_dgghrd (f08wec) to reduce the matrix pair to the generalized Hessenberg form and nag_dhgeqz (f08xec) to compute the eigenvalues via the $QZ$ algorithm.
The computation of generalized eigenvectors is done by calling nag_dtgevc (f08ykc) to compute the eigenvectors of the balanced matrix pair. The function nag_dggbak (f08wjc) is called to backward transform the eigenvectors to the user-supplied matrix pair. If both left and right eigenvectors are required then nag_dggbak (f08wjc) must be called twice.

### 10.1Program Text

Program Text (f08ykce.c)

### 10.2Program Data

Program Data (f08ykce.d)

### 10.3Program Results

Program Results (f08ykce.r)

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