NAG FL Interface
f08nvf (zgebal)
1
Purpose
f08nvf balances a complex general matrix in order to improve the accuracy of computed eigenvalues and/or eigenvectors.
2
Specification
Fortran Interface
Integer, Intent (In) 
:: 
n, lda 
Integer, Intent (Out) 
:: 
ilo, ihi, info 
Real (Kind=nag_wp), Intent (Out) 
:: 
scale(n) 
Complex (Kind=nag_wp), Intent (Inout) 
:: 
a(lda,*) 
Character (1), Intent (In) 
:: 
job 

C Header Interface
#include <nag.h>
void 
f08nvf_ (const char *job, const Integer *n, Complex a[], const Integer *lda, Integer *ilo, Integer *ihi, double scal[], Integer *info, const Charlen length_job) 

C++ Header Interface
#include <nag.h> extern "C" {
void 
f08nvf_ (const char *job, const Integer &n, Complex a[], const Integer &lda, Integer &ilo, Integer &ihi, double scal[], Integer &info, const Charlen length_job) 
}

The routine may be called by the names f08nvf, nagf_lapackeig_zgebal or its LAPACK name zgebal.
3
Description
f08nvf balances a complex general matrix
$A$. The term ‘balancing’ covers two steps, each of which involves a similarity transformation of
$A$. The routine can perform either or both of these steps.

1.The routine first attempts to permute $A$ to block upper triangular form by a similarity transformation:
where $P$ is a permutation matrix, and ${A}_{11}^{\prime}$ and ${A}_{33}^{\prime}$ are upper triangular. Then the diagonal elements of ${A}_{11}^{\prime}$ and ${A}_{33}^{\prime}$ are eigenvalues of $A$. The rest of the eigenvalues of $A$ are the eigenvalues of the central diagonal block ${A}_{22}^{\prime}$, in rows and columns ${i}_{\mathrm{lo}}$ to ${i}_{\mathrm{hi}}$. Subsequent operations to compute the eigenvalues of $A$ (or its Schur factorization) need only be applied to these rows and columns; this can save a significant amount of work if ${i}_{\mathrm{lo}}>1$ and ${i}_{\mathrm{hi}}<n$. If no suitable permutation exists (as is often the case), the routine sets ${i}_{\mathrm{lo}}=1$ and ${i}_{\mathrm{hi}}=n$, and ${A}_{22}^{\prime}$ is the whole of $A$.

2.The routine applies a diagonal similarity transformation to ${A}^{\prime}$, to make the rows and columns of ${A}_{22}^{\prime}$ as close in norm as possible:
This scaling can reduce the norm of the matrix (i.e., $\Vert {A}_{22}^{\prime \prime}\Vert <\Vert {A}_{22}^{\prime}\Vert $) and hence reduce the effect of rounding errors on the accuracy of computed eigenvalues and eigenvectors.
4
References
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
5
Arguments

1:
$\mathbf{job}$ – Character(1)
Input

On entry: indicates whether
$A$ is to be permuted and/or scaled (or neither).
 ${\mathbf{job}}=\text{'N'}$
 $A$ is neither permuted nor scaled (but values are assigned to ilo, ihi and scale).
 ${\mathbf{job}}=\text{'P'}$
 $A$ is permuted but not scaled.
 ${\mathbf{job}}=\text{'S'}$
 $A$ is scaled but not permuted.
 ${\mathbf{job}}=\text{'B'}$
 $A$ is both permuted and scaled.
Constraint:
${\mathbf{job}}=\text{'N'}$, $\text{'P'}$, $\text{'S'}$ or $\text{'B'}$.

2:
$\mathbf{n}$ – Integer
Input

On entry: $n$, the order of the matrix $A$.
Constraint:
${\mathbf{n}}\ge 0$.

3:
$\mathbf{a}\left({\mathbf{lda}},*\right)$ – Complex (Kind=nag_wp) array
Input/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 $n$ by $n$ matrix $A$.
On exit:
a is overwritten by the balanced matrix. If
${\mathbf{job}}=\text{'N'}$,
a is not referenced.

4:
$\mathbf{lda}$ – Integer
Input

On entry: the first dimension of the array
a as declared in the (sub)program from which
f08nvf is called.
Constraint:
${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.

5:
$\mathbf{ilo}$ – Integer
Output

6:
$\mathbf{ihi}$ – Integer
Output

On exit: the values
${i}_{\mathrm{lo}}$ and
${i}_{\mathrm{hi}}$ such that on exit
${\mathbf{a}}\left(i,j\right)$ is zero if
$i>j$ and
$1\le j<{i}_{\mathrm{lo}}$ or
${i}_{\mathrm{hi}}<i\le n$.
If ${\mathbf{job}}=\text{'N'}$ or $\text{'S'}$, ${i}_{\mathrm{lo}}=1$ and ${i}_{\mathrm{hi}}=n$.

7:
$\mathbf{scale}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) array
Output

On exit: details of the permutations and scaling factors applied to
$A$. More precisely, if
${p}_{j}$ is the index of the row and column interchanged with row and column
$j$ and
${d}_{j}$ is the scaling factor used to balance row and column
$j$ then
The order in which the interchanges are made is
$n$ to
${i}_{\mathrm{hi}}+1$ then
$1$ to
${i}_{\mathrm{lo}}1$.

8:
$\mathbf{info}$ – Integer
Output

On exit:
${\mathbf{info}}=0$ unless the routine detects an error (see
Section 6).
6
Error 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.
7
Accuracy
The errors are negligible, compared with those in subsequent computations.
8
Parallelism and Performance
f08nvf 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 implementationspecific information.
If the matrix
$A$ is balanced by
f08nvf, then any eigenvectors computed subsequently are eigenvectors of the matrix
${A}^{\prime \prime}$ (see
Section 3) and hence
f08nwf
must then be called to transform them back to eigenvectors of
$A$.
If the Schur vectors of
$A$ are required, then this routine must
not be called with
${\mathbf{job}}=\text{'S'}$ or
$\text{'B'}$, because then the balancing transformation is not unitary. If this routine is called with
${\mathbf{job}}=\text{'P'}$, then any Schur vectors computed subsequently are Schur vectors of the matrix
${A}^{\prime \prime}$, and
f08nwf must be called (with
${\mathbf{side}}=\text{'R'}$)
to transform them back to Schur vectors of
$A$.
The total number of real floatingpoint operations is approximately proportional to ${n}^{2}$.
The real analogue of this routine is
f08nhf.
10
Example
This example computes all the eigenvalues and right eigenvectors of the matrix
$A$, where
The program first calls
f08nvf to balance the matrix; it then computes the Schur factorization of the balanced matrix, by reduction to Hessenberg form and the
$QR$ algorithm. Then it calls
f08qxf to compute the right eigenvectors of the balanced matrix, and finally calls
f08nwf to transform the eigenvectors back to eigenvectors of the original matrix
$A$.
10.1
Program Text
10.2
Program Data
10.3
Program Results