F08 Chapter Contents
F08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF08WVF (ZGGBAL)

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

F08WVF (ZGGBAL) balances a pair of complex square matrices $\left(A,B\right)$ of order $n$. Balancing usually improves the accuracy of computed generalized eigenvalues and eigenvectors.

## 2  Specification

 SUBROUTINE F08WVF ( JOB, N, A, LDA, B, LDB, ILO, IHI, LSCALE, RSCALE, WORK, INFO)
 INTEGER N, LDA, LDB, ILO, IHI, INFO REAL (KIND=nag_wp) LSCALE(N), RSCALE(N), WORK(6*N) COMPLEX (KIND=nag_wp) A(LDA,*), B(LDB,*) CHARACTER(1) JOB
The routine may be called by its LAPACK name zggbal.

## 3  Description

Balancing may reduce the $1$-norm of the matrices and improve the accuracy of the computed eigenvalues and eigenvectors in the complex generalized eigenvalue problem
 $Ax=λBx.$
F08WVF (ZGGBAL) is usually the first step in the solution of the above generalized eigenvalue problem. Balancing is optional but it is highly recommended.
The term ‘balancing’ covers two steps, each of which involves similarity transformations on $A$ and $B$. The routine can perform either or both of these steps. Both steps are optional.
1. The routine first attempts to permute $A$ and $B$ to block upper triangular form by a similarity transformation:
 $PAPT=F= F11 F12 F13 F22 F23 F33$
 $PBPT=G= G11 G12 G13 G22 G23 G33$
where $P$ is a permutation matrix, ${F}_{11}$, ${F}_{33}$, ${G}_{11}$ and ${G}_{33}$ are upper triangular. Then the diagonal elements of the matrix pairs $\left({F}_{11},{G}_{11}\right)$ and $\left({F}_{33},{G}_{33}\right)$ are generalized eigenvalues of $\left(A,B\right)$. The rest of the generalized eigenvalues are given by the matrix pair $\left({F}_{22},{G}_{22}\right)$ which are in rows and columns ${i}_{\mathrm{lo}}$ to ${i}_{\mathrm{hi}}$. Subsequent operations to compute the generalized eigenvalues of $\left(A,B\right)$ need only be applied to the matrix pair $\left({F}_{22},{G}_{22}\right)$; this can save a significant amount of work if ${i}_{\mathrm{lo}}>1$ and ${i}_{\mathrm{hi}}. If no suitable permutation exists (as is often the case), the routine sets ${i}_{\mathrm{lo}}=1$ and ${i}_{\mathrm{hi}}=n$.
2. The routine applies a diagonal similarity transformation to $\left(F,G\right)$, to make the rows and columns of $\left({F}_{22},{G}_{22}\right)$ as close in norm as possible:
 $DFD^= I 0 0 0 D22 0 0 0 I F11 F12 F13 F22 F23 F33 I 0 0 0 D^22 0 0 0 I$
 $DGD-1= I 0 0 0 D22 0 0 0 I G11 G12 G13 G22 G23 G33 I 0 0 0 D^22 0 0 0 I$
This transformation usually improves the accuracy of computed generalized eigenvalues and eigenvectors.

## 4  References

Ward R C (1981) Balancing the generalized eigenvalue problem SIAM J. Sci. Stat. Comp. 2 141–152

## 5  Parameters

1:     JOB – CHARACTER(1)Input
On entry: specifies the operations to be performed on matrices $A$ and $B$.
${\mathbf{JOB}}=\text{'N'}$
No balancing is done. Initialize ${\mathbf{ILO}}=1$, ${\mathbf{IHI}}={\mathbf{N}}$, ${\mathbf{LSCALE}}\left(\mathit{i}\right)=1.0$ and ${\mathbf{RSCALE}}\left(\mathit{i}\right)=1.0$, for $\mathit{i}=1,2,\dots ,n$.
${\mathbf{JOB}}=\text{'P'}$
Only permutations are used in balancing.
${\mathbf{JOB}}=\text{'S'}$
Only scalings are are used in balancing.
${\mathbf{JOB}}=\text{'B'}$
Both permutations and scalings are used in balancing.
Constraint: ${\mathbf{JOB}}=\text{'N'}$, $\text{'P'}$, $\text{'S'}$ or $\text{'B'}$.
2:     N – INTEGERInput
On entry: $n$, the order of the matrices $A$ and $B$.
Constraint: ${\mathbf{N}}\ge 0$.
3:     A(LDA,$*$) – COMPLEX (KIND=nag_wp) arrayInput/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:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F08WVF (ZGGBAL) is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
5:     B(LDB,$*$) – COMPLEX (KIND=nag_wp) arrayInput/Output
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 $n$ by $n$ matrix $B$.
On exit: B is overwritten by the balanced matrix. If ${\mathbf{JOB}}=\text{'N'}$, B is not referenced.
6:     LDB – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which F08WVF (ZGGBAL) is called.
Constraint: ${\mathbf{LDB}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
7:     ILO – INTEGEROutput
8:     IHI – INTEGEROutput
On exit: ${i}_{\mathrm{lo}}$ and ${i}_{\mathrm{hi}}$ are set such that ${\mathbf{A}}\left(i,j\right)=0$ and ${\mathbf{B}}\left(i,j\right)=0$ if $i>j$ and $1\le j<{i}_{\mathrm{lo}}$ or ${i}_{\mathrm{hi}}.
If ${\mathbf{JOB}}=\text{'N'}$ or $\text{'S'}$, ${i}_{\mathrm{lo}}=1$ and ${i}_{\mathrm{hi}}=n$.
9:     LSCALE(N) – REAL (KIND=nag_wp) arrayOutput
On exit: details of the permutations and scaling factors applied to the left side of the matrices $A$ and $B$. If ${P}_{i}$ is the index of the row interchanged with row $i$ and ${d}_{i}$ is the scaling factor applied to row $i$, then
• ${\mathbf{LSCALE}}\left(\mathit{i}\right)={P}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathit{i}}_{\mathrm{lo}}-1$;
• ${\mathbf{LSCALE}}\left(\mathit{i}\right)={\mathit{d}}_{\mathit{i}}$, for $\mathit{i}={\mathit{i}}_{\mathrm{lo}},\dots ,{\mathit{i}}_{\mathrm{hi}}$;
• ${\mathbf{LSCALE}}\left(\mathit{i}\right)={P}_{\mathit{i}}$, for $\mathit{i}={\mathit{i}}_{\mathrm{hi}}+1,\dots ,n$.
The order in which the interchanges are made is $n$ to ${i}_{\mathrm{hi}}+1$, then $1$ to ${i}_{\mathrm{lo}}-1$.
10:   RSCALE(N) – REAL (KIND=nag_wp) arrayOutput
On exit: details of the permutations and scaling factors applied to the right side of the matrices $A$ and $B$.
If ${P}_{j}$ is the index of the column interchanged with column $j$ and ${\stackrel{^}{d}}_{j}$ is the scaling factor applied to column $j$, then
• ${\mathbf{RSCALE}}\left(\mathit{j}\right)={P}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathit{i}}_{\mathrm{lo}}-1$;
• ${\mathbf{RSCALE}}\left(\mathit{j}\right)={\stackrel{^}{d}}_{\mathit{j}}$, for $\mathit{j}={i}_{\mathrm{lo}},\dots ,{i}_{\mathrm{hi}}$;
• ${\mathbf{RSCALE}}\left(\mathit{j}\right)={P}_{\mathit{j}}$, for $\mathit{j}={i}_{\mathrm{hi}}+1,\dots ,n$.
The order in which the interchanges are made is $n$ to ${i}_{\mathrm{hi}}+1$, then $1$ to ${i}_{\mathrm{lo}}-1$.
11:   WORK($6×{\mathbf{N}}$) – REAL (KIND=nag_wp) arrayWorkspace
12:   INFO – INTEGEROutput
On exit: ${\mathbf{INFO}}=0$ unless the routine detects an error (see Section 6).

## 6  Error Indicators and Warnings

Errors or warnings detected by the routine:
${\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 to those in subsequent computations.

F08WVF (ZGGBAL) is usually the first step in computing the complex generalized eigenvalue problem but it is an optional step. The matrix $B$ is reduced to the triangular form using the $QR$ factorization routine F08ASF (ZGEQRF) and the unitary transformation $Q$ is applied to the matrix $A$ by calling F08AUF (ZUNMQR). This is followed by F08WSF (ZGGHRD) which reduces the matrix pair into the generalized Hessenberg form.
If the matrix pair $\left(A,B\right)$ is balanced by this routine, then any generalized eigenvectors computed subsequently are eigenvectors of the balanced matrix pair. In that case, to compute the generalized eigenvectors of the original matrix, F08WWF (ZGGBAK) must be called.
The total number of floating point operations is approximately proportional to ${n}^{2}$.
The real analogue of this routine is F08WHF (DGGBAL).

## 9  Example

See Section 9 in F08XSF (ZHGEQZ) and F08YXF (ZTGEVC).