Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_lapack_zgeevx (f08np)

## Purpose

nag_lapack_zgeevx (f08np) computes the eigenvalues and, optionally, the left and/or right eigenvectors for an n$n$ by n$n$ complex nonsymmetric matrix A$A$.
Optionally, it also computes a balancing transformation to improve the conditioning of the eigenvalues and eigenvectors, reciprocal condition numbers for the eigenvalues, and reciprocal condition numbers for the right eigenvectors.

## Syntax

[a, w, vl, vr, ilo, ihi, scale, abnrm, rconde, rcondv, info] = f08np(balanc, jobvl, jobvr, sense, a, 'n', n)
[a, w, vl, vr, ilo, ihi, scale, abnrm, rconde, rcondv, info] = nag_lapack_zgeevx(balanc, jobvl, jobvr, sense, a, 'n', n)

## Description

The right eigenvector vj${v}_{j}$ of A$A$ satisfies
 A vj = λj vj $A vj = λj vj$
where λj${\lambda }_{j}$ is the j$j$th eigenvalue of A$A$. The left eigenvector uj${u}_{j}$ of A$A$ satisfies
 ujH A = λj ujH $ujH A = λj ujH$
where ujH${u}_{j}^{\mathrm{H}}$ denotes the conjugate transpose of uj${u}_{j}$.
Balancing a matrix means permuting the rows and columns to make it more nearly upper triangular, and applying a diagonal similarity transformation DAD1$DA{D}^{-1}$, where D$D$ is a diagonal matrix, with the aim of making its rows and columns closer in norm and the condition numbers of its eigenvalues and eigenvectors smaller. The computed reciprocal condition numbers correspond to the balanced matrix. Permuting rows and columns will not change the condition numbers (in exact arithmetic) but diagonal scaling will. For further explanation of balancing, see Section 4.8.1.2 of Anderson et al. (1999).
Following the optional balancing, the matrix A$A$ is first reduced to upper Hessenberg form by means of unitary similarity transformations, and the QR$QR$ algorithm is then used to further reduce the matrix to upper triangular Schur form, T$T$, from which the eigenvalues are computed. Optionally, the eigenvectors of T$T$ are also computed and backtransformed to those of A$A$.

## 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 (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## Parameters

### Compulsory Input Parameters

1:     balanc – string (length ≥ 1)
Indicates how the input matrix should be diagonally scaled and/or permuted to improve the conditioning of its eigenvalues.
balanc = 'N'${\mathbf{balanc}}=\text{'N'}$
Do not diagonally scale or permute.
balanc = 'P'${\mathbf{balanc}}=\text{'P'}$
Perform permutations to make the matrix more nearly upper triangular. Do not diagonally scale.
balanc = 'S'${\mathbf{balanc}}=\text{'S'}$
Diagonally scale the matrix, i.e., replace A$A$ by DAD1$DA{D}^{-1}$, where D$D$ is a diagonal matrix chosen to make the rows and columns of A$A$ more equal in norm. Do not permute.
balanc = 'B'${\mathbf{balanc}}=\text{'B'}$
Both diagonally scale and permute A$A$.
Computed reciprocal condition numbers will be for the matrix after balancing and/or permuting. Permuting does not change condition numbers (in exact arithmetic), but balancing does.
Constraint: balanc = 'N'${\mathbf{balanc}}=\text{'N'}$, 'P'$\text{'P'}$, 'S'$\text{'S'}$ or 'B'$\text{'B'}$.
2:     jobvl – string (length ≥ 1)
If jobvl = 'N'${\mathbf{jobvl}}=\text{'N'}$, the left eigenvectors of A$A$ are not computed.
If jobvl = 'V'${\mathbf{jobvl}}=\text{'V'}$, the left eigenvectors of A$A$ are computed.
If sense = 'E'${\mathbf{sense}}=\text{'E'}$ or 'B'$\text{'B'}$, jobvl must be set to jobvl = 'V'${\mathbf{jobvl}}=\text{'V'}$.
Constraint: jobvl = 'N'${\mathbf{jobvl}}=\text{'N'}$ or 'V'$\text{'V'}$.
3:     jobvr – string (length ≥ 1)
If jobvr = 'N'${\mathbf{jobvr}}=\text{'N'}$, the right eigenvectors of A$A$ are not computed.
If jobvr = 'V'${\mathbf{jobvr}}=\text{'V'}$, the right eigenvectors of A$A$ are computed.
If sense = 'E'${\mathbf{sense}}=\text{'E'}$ or 'B'$\text{'B'}$, jobvr must be set to jobvr = 'V'${\mathbf{jobvr}}=\text{'V'}$.
Constraint: jobvr = 'N'${\mathbf{jobvr}}=\text{'N'}$ or 'V'$\text{'V'}$.
4:     sense – string (length ≥ 1)
Determines which reciprocal condition numbers are computed.
sense = 'N'${\mathbf{sense}}=\text{'N'}$
None are computed.
sense = 'E'${\mathbf{sense}}=\text{'E'}$
Computed for eigenvalues only.
sense = 'V'${\mathbf{sense}}=\text{'V'}$
Computed for right eigenvectors only.
sense = 'B'${\mathbf{sense}}=\text{'B'}$
Computed for eigenvalues and right eigenvectors.
If sense = 'E'${\mathbf{sense}}=\text{'E'}$ or 'B'$\text{'B'}$, both left and right eigenvectors must also be computed (jobvl = 'V'${\mathbf{jobvl}}=\text{'V'}$ and jobvr = 'V'${\mathbf{jobvr}}=\text{'V'}$).
Constraint: sense = 'N'${\mathbf{sense}}=\text{'N'}$, 'E'$\text{'E'}$, 'V'$\text{'V'}$ or 'B'$\text{'B'}$.
5:     a(lda, : $:$) – complex array
The first dimension of the array a must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The n$n$ by n$n$ matrix A$A$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the array a and the second dimension of the array a. (An error is raised if these dimensions are not equal.)
n$n$, the order of the matrix A$A$.
Constraint: n0${\mathbf{n}}\ge 0$.

### Input Parameters Omitted from the MATLAB Interface

lda ldvl ldvr work lwork rwork

### Output Parameters

1:     a(lda, : $:$) – complex array
The first dimension of the array a will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
ldamax (1,n)$\mathit{lda}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
a has been overwritten. If jobvl = 'V'${\mathbf{jobvl}}=\text{'V'}$ or jobvr = 'V'${\mathbf{jobvr}}=\text{'V'}$, A$A$ contains the Schur form of the balanced version of the matrix A$A$.
2:     w( : $:$) – complex array
Note: the dimension of the array w must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
Contains the computed eigenvalues.
3:     vl(ldvl, : $:$) – complex array
The first dimension, ldvl, of the array vl will be
• if jobvl = 'V'${\mathbf{jobvl}}=\text{'V'}$, ldvl max (1,n) $\mathit{ldvl}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ldvl1$\mathit{ldvl}\ge 1$.
The second dimension of the array will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if jobvl = 'V'${\mathbf{jobvl}}=\text{'V'}$, and at least 1$1$ otherwise
If jobvl = 'V'${\mathbf{jobvl}}=\text{'V'}$, the left eigenvectors uj${u}_{j}$ are stored one after another in the columns of vl, in the same order as their corresponding eigenvalues; that is uj = vl( : ,j)${u}_{j}={\mathbf{vl}}\left(:,j\right)$, the j$j$th column of vl.
If jobvl = 'N'${\mathbf{jobvl}}=\text{'N'}$, vl is not referenced.
4:     vr(ldvr, : $:$) – complex array
The first dimension, ldvr, of the array vr will be
• if jobvr = 'V'${\mathbf{jobvr}}=\text{'V'}$, ldvr max (1,n) $\mathit{ldvr}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise ldvr1$\mathit{ldvr}\ge 1$.
The second dimension of the array will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if jobvr = 'V'${\mathbf{jobvr}}=\text{'V'}$, and at least 1$1$ otherwise
If jobvr = 'V'${\mathbf{jobvr}}=\text{'V'}$, the right eigenvectors vj${v}_{j}$ are stored one after another in the columns of vr, in the same order as their corresponding eigenvalues; that is vj = vr( : ,j)${v}_{j}={\mathbf{vr}}\left(:,j\right)$, the j$j$th column of vr.
If jobvr = 'N'${\mathbf{jobvr}}=\text{'N'}$, vr is not referenced.
5:     ilo – int64int32nag_int scalar
6:     ihi – int64int32nag_int scalar
ilo and ihi are integer values determined when A$A$ was balanced. The balanced A$A$ has aij = 0${a}_{ij}=0$ if i > j$i>j$ and j = 1,2,,ilo1$j=1,2,\dots ,{\mathbf{ilo}}-1$ or i = ihi + 1,,n$i={\mathbf{ihi}}+1,\dots ,{\mathbf{n}}$.
7:     scale( : $:$) – double array
Note: the dimension of the array scale must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
Details of the permutations and scaling factors applied when balancing A$A$.
If pj${p}_{j}$ is the index of the row and column interchanged with row and column j$j$, and dj${d}_{j}$ is the scaling factor applied to row and column j$j$, then
• scale(j) = pj${\mathbf{scale}}\left(\mathit{j}\right)={p}_{\mathit{j}}$, for j = 1,2,,ilo1$\mathit{j}=1,2,\dots ,{\mathbf{ilo}}-1$;
• scale(j) = dj${\mathbf{scale}}\left(\mathit{j}\right)={d}_{\mathit{j}}$, for j = ilo,,ihi$\mathit{j}={\mathbf{ilo}},\dots ,{\mathbf{ihi}}$;
• scale(j) = pj${\mathbf{scale}}\left(\mathit{j}\right)={p}_{\mathit{j}}$, for j = ihi + 1,,n$\mathit{j}={\mathbf{ihi}}+1,\dots ,{\mathbf{n}}$.
The order in which the interchanges are made is n to ihi + 1${\mathbf{ihi}}+1$, then 1$1$ to ilo1${\mathbf{ilo}}-1$.
8:     abnrm – double scalar
The 1$1$-norm of the balanced matrix (the maximum of the sum of absolute values of elements of any column).
9:     rconde( : $:$) – double array
Note: the dimension of the array rconde must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
rconde(j)${\mathbf{rconde}}\left(j\right)$ is the reciprocal condition number of the j$j$th eigenvalue.
10:   rcondv( : $:$) – double array
Note: the dimension of the array rcondv must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
rcondv(j)${\mathbf{rcondv}}\left(j\right)$ is the reciprocal condition number of the j$j$th right eigenvector.
11:   info – int64int32nag_int scalar
info = 0${\mathbf{info}}=0$ unless the function detects an error (see Section [Error Indicators and Warnings]).

## Error Indicators and Warnings

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

info = i${\mathbf{info}}=-i$
If info = i${\mathbf{info}}=-i$, parameter i$i$ had an illegal value on entry. The parameters are numbered as follows:
1: balanc, 2: jobvl, 3: jobvr, 4: sense, 5: n, 6: a, 7: lda, 8: w, 9: vl, 10: ldvl, 11: vr, 12: ldvr, 13: ilo, 14: ihi, 15: scale, 16: abnrm, 17: rconde, 18: rcondv, 19: work, 20: lwork, 21: rwork, 22: info.
It is possible that info refers to a parameter that is omitted from the MATLAB interface. This usually indicates that an error in one of the other input parameters has caused an incorrect value to be inferred.
W INFO > 0${\mathbf{INFO}}>0$
If info = i${\mathbf{info}}=i$, the QR$QR$ algorithm failed to compute all the eigenvalues, and no eigenvectors or condition numbers have been computed; elements 1 : ilo1$1:{\mathbf{ilo}}-1$ and i + 1 : n$i+1:{\mathbf{n}}$ of w contain eigenvalues which have converged.

## Accuracy

The computed eigenvalues and eigenvectors are exact for a nearby matrix (A + E)$\left(A+E\right)$, where
 ‖E‖2 = O(ε) ‖A‖2 , $‖E‖2 = O(ε) ‖A‖2 ,$
and ε$\epsilon$ is the machine precision. See Section 4.8 of Anderson et al. (1999) for further details.

Each eigenvector is normalized to have Euclidean norm equal to unity and the element of largest absolute value real and positive.
The total number of floating point operations is proportional to n3${n}^{3}$.
The real analogue of this function is nag_lapack_dgeevx (f08nb).

## Example

```function nag_lapack_zgeevx_example
balanc = 'Balance';
jobvl = 'Vectors (left)';
jobvr = 'Vectors (right)';
sense = 'Both reciprocal condition numbers';
a = [ -3.97 - 5.04i,  -4.11 + 3.7i,  -0.34 + 1.01i,  1.29 - 0.86i;
0.34 - 1.5i,  1.52 - 0.43i,  1.88 - 5.38i,  3.36 + 0.65i;
3.31 - 3.85i,  2.5 + 3.45i,  0.88 - 1.08i,  0.64 - 1.48i;
-1.1 + 0.82i,  1.81 - 1.59i,  3.25 + 1.33i,  1.57 - 3.44i];
[aOut, w, vl, vr, ilo, ihi, scale, abnrm, rconde, rcondv, info] = ...
nag_lapack_zgeevx(balanc, jobvl, jobvr, sense, a)
```
```

aOut =

-6.0004 - 6.9998i  -0.3656 + 0.3637i   0.4761 - 0.1946i  -0.7237 + 0.5589i
0.0000 + 0.0000i  -5.0000 + 2.0060i   0.4981 - 0.5232i  -0.1637 + 0.2071i
0.0000 + 0.0000i   0.0000 + 0.0000i   7.9982 - 0.9964i   0.8487 - 0.6651i
0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   3.0023 - 3.9998i

w =

-6.0004 - 6.9998i
-5.0000 + 2.0060i
7.9982 - 0.9964i
3.0023 - 3.9998i

vl =

0.8357 + 0.0000i  -0.3510 + 0.1013i  -0.1689 + 0.2595i   0.1099 - 0.2007i
-0.0794 + 0.3372i  -0.4035 + 0.4540i   0.6762 + 0.0000i   0.0336 + 0.2312i
0.0917 + 0.3097i   0.6239 + 0.0000i   0.3032 + 0.5642i   0.0944 - 0.3947i
0.0456 - 0.2741i  -0.0816 - 0.3190i   0.1328 + 0.1376i   0.8534 + 0.0000i

vr =

0.8457 + 0.0000i  -0.3865 + 0.1732i  -0.1730 + 0.2669i  -0.0356 - 0.1782i
-0.0177 + 0.3036i  -0.3539 + 0.4529i   0.6924 + 0.0000i   0.1264 + 0.2666i
0.0875 + 0.3115i   0.6124 + 0.0000i   0.3324 + 0.4960i   0.0129 - 0.2966i
-0.0561 - 0.2906i  -0.0859 - 0.3284i   0.2504 - 0.0147i   0.8898 + 0.0000i

ilo =

1

ihi =

4

scale =

1
1
1
1

abnrm =

14.4031

rconde =

0.9932
0.9964
0.9814
0.9779

rcondv =

8.4011
8.0214
5.8292
5.8292

info =

0

```
```function f08np_example
balanc = 'Balance';
jobvl = 'Vectors (left)';
jobvr = 'Vectors (right)';
sense = 'Both reciprocal condition numbers';
a = [ -3.97 - 5.04i,  -4.11 + 3.7i,  -0.34 + 1.01i,  1.29 - 0.86i;
0.34 - 1.5i,  1.52 - 0.43i,  1.88 - 5.38i,  3.36 + 0.65i;
3.31 - 3.85i,  2.5 + 3.45i,  0.88 - 1.08i,  0.64 - 1.48i;
-1.1 + 0.82i,  1.81 - 1.59i,  3.25 + 1.33i,  1.57 - 3.44i];
[aOut, w, vl, vr, ilo, ihi, scale, abnrm, rconde, rcondv, info] = ...
f08np(balanc, jobvl, jobvr, sense, a)
```
```

aOut =

-6.0004 - 6.9998i  -0.3656 + 0.3637i   0.4761 - 0.1946i  -0.7237 + 0.5589i
0.0000 + 0.0000i  -5.0000 + 2.0060i   0.4981 - 0.5232i  -0.1637 + 0.2071i
0.0000 + 0.0000i   0.0000 + 0.0000i   7.9982 - 0.9964i   0.8487 - 0.6651i
0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   3.0023 - 3.9998i

w =

-6.0004 - 6.9998i
-5.0000 + 2.0060i
7.9982 - 0.9964i
3.0023 - 3.9998i

vl =

0.8357 + 0.0000i  -0.3510 + 0.1013i  -0.1689 + 0.2595i   0.1099 - 0.2007i
-0.0794 + 0.3372i  -0.4035 + 0.4540i   0.6762 + 0.0000i   0.0336 + 0.2312i
0.0917 + 0.3097i   0.6239 + 0.0000i   0.3032 + 0.5642i   0.0944 - 0.3947i
0.0456 - 0.2741i  -0.0816 - 0.3190i   0.1328 + 0.1376i   0.8534 + 0.0000i

vr =

0.8457 + 0.0000i  -0.3865 + 0.1732i  -0.1730 + 0.2669i  -0.0356 - 0.1782i
-0.0177 + 0.3036i  -0.3539 + 0.4529i   0.6924 + 0.0000i   0.1264 + 0.2666i
0.0875 + 0.3115i   0.6124 + 0.0000i   0.3324 + 0.4960i   0.0129 - 0.2966i
-0.0561 - 0.2906i  -0.0859 - 0.3284i   0.2504 - 0.0147i   0.8898 + 0.0000i

ilo =

1

ihi =

4

scale =

1
1
1
1

abnrm =

14.4031

rconde =

0.9932
0.9964
0.9814
0.9779

rcondv =

8.4011
8.0214
5.8292
5.8292

info =

0

```