﻿ f08np Method
f08np computes the eigenvalues and, optionally, the left and/or right eigenvectors for an $n$ by $n$ complex nonsymmetric matrix $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

C#
```public static void f08np(
string balanc,
string jobvl,
string jobvr,
string sense,
int n,
Complex[,] a,
Complex[] w,
Complex[,] vl,
Complex[,] vr,
out int ilo,
out int ihi,
double[] scale,
out double abnrm,
double[] rconde,
double[] rcondv,
out int info
)```
Visual Basic
```Public Shared Sub f08np ( _
balanc As String, _
jobvl As String, _
jobvr As String, _
sense As String, _
n As Integer, _
a As Complex(,), _
w As Complex(), _
vl As Complex(,), _
vr As Complex(,), _
<OutAttribute> ByRef ilo As Integer, _
<OutAttribute> ByRef ihi As Integer, _
scale As Double(), _
<OutAttribute> ByRef abnrm As Double, _
rconde As Double(), _
rcondv As Double(), _
<OutAttribute> ByRef info As Integer _
)```
Visual C++
```public:
static void f08np(
String^ balanc,
String^ jobvl,
String^ jobvr,
String^ sense,
int n,
array<Complex,2>^ a,
array<Complex>^ w,
array<Complex,2>^ vl,
array<Complex,2>^ vr,
[OutAttribute] int% ilo,
[OutAttribute] int% ihi,
array<double>^ scale,
[OutAttribute] double% abnrm,
array<double>^ rconde,
array<double>^ rcondv,
[OutAttribute] int% info
)```
F#
```static member f08np :
balanc : string *
jobvl : string *
jobvr : string *
sense : string *
n : int *
a : Complex[,] *
w : Complex[] *
vl : Complex[,] *
vr : Complex[,] *
ilo : int byref *
ihi : int byref *
scale : float[] *
abnrm : float byref *
rconde : float[] *
rcondv : float[] *
info : int byref -> unit
```

Parameters

balanc
Type: System..::..String
On entry: indicates how the input matrix should be diagonally scaled and/or permuted to improve the conditioning of its eigenvalues.
${\mathbf{balanc}}=\text{"N"}$
Do not diagonally scale or permute.
${\mathbf{balanc}}=\text{"P"}$
Perform permutations to make the matrix more nearly upper triangular. Do not diagonally scale.
${\mathbf{balanc}}=\text{"S"}$
Diagonally scale the matrix, i.e., replace $A$ by $DA{D}^{-1}$, where $D$ is a diagonal matrix chosen to make the rows and columns of $A$ more equal in norm. Do not permute.
${\mathbf{balanc}}=\text{"B"}$
Both diagonally scale and permute $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: ${\mathbf{balanc}}=\text{"N"}$, $\text{"P"}$, $\text{"S"}$ or $\text{"B"}$.
jobvl
Type: System..::..String
On entry: if ${\mathbf{jobvl}}=\text{"N"}$, the left eigenvectors of $A$ are not computed.
If ${\mathbf{jobvl}}=\text{"V"}$, the left eigenvectors of $A$ are computed.
If ${\mathbf{sense}}=\text{"E"}$ or $\text{"B"}$, jobvl must be set to ${\mathbf{jobvl}}=\text{"V"}$.
Constraint: ${\mathbf{jobvl}}=\text{"N"}$ or $\text{"V"}$.
jobvr
Type: System..::..String
On entry: if ${\mathbf{jobvr}}=\text{"N"}$, the right eigenvectors of $A$ are not computed.
If ${\mathbf{jobvr}}=\text{"V"}$, the right eigenvectors of $A$ are computed.
If ${\mathbf{sense}}=\text{"E"}$ or $\text{"B"}$, jobvr must be set to ${\mathbf{jobvr}}=\text{"V"}$.
Constraint: ${\mathbf{jobvr}}=\text{"N"}$ or $\text{"V"}$.
sense
Type: System..::..String
On entry: determines which reciprocal condition numbers are computed.
${\mathbf{sense}}=\text{"N"}$
None are computed.
${\mathbf{sense}}=\text{"E"}$
Computed for eigenvalues only.
${\mathbf{sense}}=\text{"V"}$
Computed for right eigenvectors only.
${\mathbf{sense}}=\text{"B"}$
Computed for eigenvalues and right eigenvectors.
If ${\mathbf{sense}}=\text{"E"}$ or $\text{"B"}$, both left and right eigenvectors must also be computed (${\mathbf{jobvl}}=\text{"V"}$ and ${\mathbf{jobvr}}=\text{"V"}$).
Constraint: ${\mathbf{sense}}=\text{"N"}$, $\text{"E"}$, $\text{"V"}$ or $\text{"B"}$.
n
Type: System..::..Int32
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 0$.
a
Type: array<NagLibrary..::..Complex,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
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 $n$ by $n$ matrix $A$.
On exit: a has been overwritten. If ${\mathbf{jobvl}}=\text{"V"}$ or ${\mathbf{jobvr}}=\text{"V"}$, $A$ contains the Schur form of the balanced version of the matrix $A$.
w
Type: array<NagLibrary..::..Complex>[]()[][]
An array of size [dim1]
Note: the dimension of the array w must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On exit: contains the computed eigenvalues.
vl
Type: array<NagLibrary..::..Complex,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint:
• if ${\mathbf{jobvl}}=\text{"V"}$, $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise $\mathrm{dim1}\ge 1$.
Note: the second dimension of the array vl must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{jobvl}}=\text{"V"}$, and at least $1$ otherwise.
On exit: if ${\mathbf{jobvl}}=\text{"V"}$, the left eigenvectors ${u}_{j}$ are stored one after another in the columns of vl, in the same order as their corresponding eigenvalues; that is ${u}_{j}={\mathbf{vl}}\left[\mathit{i}-1,j-1\right]$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
If ${\mathbf{jobvl}}=\text{"N"}$, vl is not referenced.
vr
Type: array<NagLibrary..::..Complex,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint:
• if ${\mathbf{jobvr}}=\text{"V"}$, $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• otherwise $\mathrm{dim1}\ge 1$.
Note: the second dimension of the array vr must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{jobvr}}=\text{"V"}$, and at least $1$ otherwise.
On exit: if ${\mathbf{jobvr}}=\text{"V"}$, the right eigenvectors ${v}_{j}$ are stored one after another in the columns of vr, in the same order as their corresponding eigenvalues; that is ${v}_{j}={\mathbf{vr}}\left[\mathit{i}-1,j-1\right]$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
If ${\mathbf{jobvr}}=\text{"N"}$, vr is not referenced.
ilo
Type: System..::..Int32%
On exit: ilo and ihi are integer values determined when $A$ was balanced. The balanced $A$ has ${a}_{ij}=0$ if $i>j$ and $j=1,2,\dots ,{\mathbf{ilo}}-1$ or $i={\mathbf{ihi}}+1,\dots ,{\mathbf{n}}$.
ihi
Type: System..::..Int32%
On exit: ilo and ihi are integer values determined when $A$ was balanced. The balanced $A$ has ${a}_{ij}=0$ if $i>j$ and $j=1,2,\dots ,{\mathbf{ilo}}-1$ or $i={\mathbf{ihi}}+1,\dots ,{\mathbf{n}}$.
scale
Type: array<System..::..Double>[]()[][]
An array of size [dim1]
Note: the dimension of the array scale must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On exit: details of the permutations and scaling factors applied when balancing $A$.
If ${p}_{j}$ is the index of the row and column interchanged with row and column $j$, and ${d}_{j}$ is the scaling factor applied to row and column $j$, then
• ${\mathbf{scale}}\left[\mathit{j}-1\right]={p}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{ilo}}-1$;
• ${\mathbf{scale}}\left[\mathit{j}-1\right]={d}_{\mathit{j}}$, for $\mathit{j}={\mathbf{ilo}},\dots ,{\mathbf{ihi}}$;
• ${\mathbf{scale}}\left[\mathit{j}-1\right]={p}_{\mathit{j}}$, for $\mathit{j}={\mathbf{ihi}}+1,\dots ,{\mathbf{n}}$.
The order in which the interchanges are made is n to ${\mathbf{ihi}}+1$, then $1$ to ${\mathbf{ilo}}-1$.
abnrm
Type: System..::..Double%
On exit: the $1$-norm of the balanced matrix (the maximum of the sum of absolute values of elements of any column).
rconde
Type: array<System..::..Double>[]()[][]
An array of size [dim1]
Note: the dimension of the array rconde must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On exit: ${\mathbf{rconde}}\left[j-1\right]$ is the reciprocal condition number of the $j$th eigenvalue.
rcondv
Type: array<System..::..Double>[]()[][]
An array of size [dim1]
Note: the dimension of the array rcondv must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On exit: ${\mathbf{rcondv}}\left[j-1\right]$ is the reciprocal condition number of the $j$th right eigenvector.
info
Type: System..::..Int32%
On exit: ${\mathbf{info}}=0$ unless the method detects an error (see [Error Indicators and Warnings]).

Description

The right eigenvector ${v}_{j}$ of $A$ satisfies
 $Avj=λjvj$
where ${\lambda }_{j}$ is the $j$th eigenvalue of $A$. The left eigenvector ${u}_{j}$ of $A$ satisfies
 $ujHA=λjujH$
where ${u}_{j}^{\mathrm{H}}$ denotes the conjugate transpose of ${u}_{j}$.
Balancing a matrix means permuting the rows and columns to make it more nearly upper triangular, and applying a diagonal similarity transformation $DA{D}^{-1}$, where $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$ is first reduced to upper Hessenberg form by means of unitary similarity transformations, and the $QR$ algorithm is then used to further reduce the matrix to upper triangular Schur form, $T$, from which the eigenvalues are computed. Optionally, the eigenvectors of $T$ are also computed and backtransformed to those of $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

Error Indicators and Warnings

Some error messages may refer to parameters that are dropped from this interface (LDA, LDVL, LDVR) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\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 $QR$ algorithm failed to compute all the eigenvalues, and no eigenvectors or condition numbers have been computed; elements $1:{\mathbf{ilo}}-1$ and $i+1:{\mathbf{n}}$ of w contain eigenvalues which have converged.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

Accuracy

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

Parallelism and Performance

None.

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 ${n}^{3}$.
The real analogue of this method is f08nb.

Example

This example finds all the eigenvalues and right eigenvectors of the matrix
 $A= -3.97-5.04i -4.11+3.70i -0.34+1.01i 1.29-0.86i 0.34-1.50i 1.52-0.43i 1.88-5.38i 3.36+0.65i 3.31-3.85i 2.50+3.45i 0.88-1.08i 0.64-1.48i -1.10+0.82i 1.81-1.59i 3.25+1.33i 1.57-3.44i ,$
together with estimates of the condition number and forward error bounds for each eigenvalue and eigenvector. The option to balance the matrix is used. In order to compute the condition numbers of the eigenvalues, the left eigenvectors also have to be computed, but they are not printed out in this example.

Example program (C#): f08npe.cs

Example program data: f08npe.d

Example program results: f08npe.r