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_zggbal (f08wv)

## Purpose

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

## Syntax

[a, b, ilo, ihi, lscale, rscale, info] = f08wv(job, a, b, 'n', n)
[a, b, ilo, ihi, lscale, rscale, info] = nag_lapack_zggbal(job, a, b, 'n', n)

## Description

Balancing may reduce the 1$1$-norm of the matrices and improve the accuracy of the computed eigenvalues and eigenvectors in the complex generalized eigenvalue problem
 Ax = λBx. $Ax=λBx.$
nag_lapack_zggbal (f08wv) 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$A$ and B$B$. The function can perform either or both of these steps. Both steps are optional.
1. The function first attempts to permute A$A$ and B$B$ to block upper triangular form by a similarity transformation:
PAPT = F =
 F11 F12 F13 F22 F23 F33
$PAPT=F= F11 F12 F13 F22 F23 F33$
PBPT = G =
 G11 G12 G13 G22 G23 G33
$PBPT=G= G11 G12 G13 G22 G23 G33$
where P$P$ is a permutation matrix, F11${F}_{11}$, F33${F}_{33}$, G11${G}_{11}$ and G33${G}_{33}$ are upper triangular. Then the diagonal elements of the matrix pairs (F11,G11)$\left({F}_{11},{G}_{11}\right)$ and (F33,G33)$\left({F}_{33},{G}_{33}\right)$ are generalized eigenvalues of (A,B)$\left(A,B\right)$. The rest of the generalized eigenvalues are given by the matrix pair (F22,G22)$\left({F}_{22},{G}_{22}\right)$ which are in rows and columns ilo${i}_{\mathrm{lo}}$ to ihi${i}_{\mathrm{hi}}$. Subsequent operations to compute the generalized eigenvalues of (A,B)$\left(A,B\right)$ need only be applied to the matrix pair (F22,G22)$\left({F}_{22},{G}_{22}\right)$; this can save a significant amount of work if ilo > 1${i}_{\mathrm{lo}}>1$ and ihi < n${i}_{\mathrm{hi}}. If no suitable permutation exists (as is often the case), the function sets ilo = 1${i}_{\mathrm{lo}}=1$ and ihi = n${i}_{\mathrm{hi}}=n$.
2. The function applies a diagonal similarity transformation to (F,G)$\left(F,G\right)$, to make the rows and columns of (F22,G22)$\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
$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
$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.

## References

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

## Parameters

### Compulsory Input Parameters

1:     job – string (length ≥ 1)
Specifies the operations to be performed on matrices A$A$ and B$B$.
job = 'N'${\mathbf{job}}=\text{'N'}$
No balancing is done. Initialize ilo = 1${\mathbf{ilo}}=1$, ihi = n${\mathbf{ihi}}={\mathbf{n}}$, lscale(i) = 1.0${\mathbf{lscale}}\left(\mathit{i}\right)=1.0$ and rscale(i) = 1.0${\mathbf{rscale}}\left(\mathit{i}\right)=1.0$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
job = 'P'${\mathbf{job}}=\text{'P'}$
Only permutations are used in balancing.
job = 'S'${\mathbf{job}}=\text{'S'}$
Only scalings are are used in balancing.
job = 'B'${\mathbf{job}}=\text{'B'}$
Both permutations and scalings are used in balancing.
Constraint: job = 'N'${\mathbf{job}}=\text{'N'}$, 'P'$\text{'P'}$, 'S'$\text{'S'}$ or 'B'$\text{'B'}$.
2:     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$.
3:     b(ldb, : $:$) – complex array
The first dimension of the array b 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 B$B$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the arrays a, b The second dimension of the arrays a, b.
n$n$, the order of the matrices A$A$ and B$B$.
Constraint: n0${\mathbf{n}}\ge 0$.

lda ldb work

### 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 stores the balanced matrix. If job = 'N'${\mathbf{job}}=\text{'N'}$, a is not referenced.
2:     b(ldb, : $:$) – complex array
The first dimension of the array b 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)$
ldbmax (1,n)$\mathit{ldb}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
b stores the balanced matrix. If job = 'N'${\mathbf{job}}=\text{'N'}$, b is not referenced.
3:     ilo – int64int32nag_int scalar
4:     ihi – int64int32nag_int scalar
ilo${i}_{\mathrm{lo}}$ and ihi${i}_{\mathrm{hi}}$ are set such that a(i,j) = 0${\mathbf{a}}\left(i,j\right)=0$ and b(i,j) = 0${\mathbf{b}}\left(i,j\right)=0$ if i > j$i>j$ and 1j < ilo$1\le j<{i}_{\mathrm{lo}}$ or ihi < in${i}_{\mathrm{hi}}.
If job = 'N'${\mathbf{job}}=\text{'N'}$ or 'S'$\text{'S'}$, ilo = 1${i}_{\mathrm{lo}}=1$ and ihi = n${i}_{\mathrm{hi}}=n$.
5:     lscale(n) – double array
Details of the permutations and scaling factors applied to the left side of the matrices A$A$ and B$B$. If Pi${P}_{i}$ is the index of the row interchanged with row i$i$ and di${d}_{i}$ is the scaling factor applied to row i$i$, then
• lscale(i) = Pi${\mathbf{lscale}}\left(\mathit{i}\right)={P}_{\mathit{i}}$, for i = 1,2,,ilo1$\mathit{i}=1,2,\dots ,{\mathit{i}}_{\mathrm{lo}}-1$;
• lscale(i) = di${\mathbf{lscale}}\left(\mathit{i}\right)={\mathit{d}}_{\mathit{i}}$, for i = ilo,,ihi$\mathit{i}={\mathit{i}}_{\mathrm{lo}},\dots ,{\mathit{i}}_{\mathrm{hi}}$;
• lscale(i) = Pi${\mathbf{lscale}}\left(\mathit{i}\right)={P}_{\mathit{i}}$, for i = ihi + 1,,n$\mathit{i}={\mathit{i}}_{\mathrm{hi}}+1,\dots ,n$.
The order in which the interchanges are made is n$n$ to ihi + 1${i}_{\mathrm{hi}}+1$, then 1$1$ to ilo1${i}_{\mathrm{lo}}-1$.
6:     rscale(n) – double array
Details of the permutations and scaling factors applied to the right side of the matrices A$A$ and B$B$.
If Pj${P}_{j}$ is the index of the column interchanged with column j$j$ and j${\stackrel{^}{d}}_{j}$ is the scaling factor applied to column j$j$, then
• rscale(j) = Pj${\mathbf{rscale}}\left(\mathit{j}\right)={P}_{\mathit{j}}$, for j = 1,2,,ilo1$\mathit{j}=1,2,\dots ,{\mathit{i}}_{\mathrm{lo}}-1$;
• rscale(j) = j${\mathbf{rscale}}\left(\mathit{j}\right)={\stackrel{^}{d}}_{\mathit{j}}$, for j = ilo,,ihi$\mathit{j}={i}_{\mathrm{lo}},\dots ,{i}_{\mathrm{hi}}$;
• rscale(j) = Pj${\mathbf{rscale}}\left(\mathit{j}\right)={P}_{\mathit{j}}$, for j = ihi + 1,,n$\mathit{j}={i}_{\mathrm{hi}}+1,\dots ,n$.
The order in which the interchanges are made is n$n$ to ihi + 1${i}_{\mathrm{hi}}+1$, then 1$1$ to ilo1${i}_{\mathrm{lo}}-1$.
7:     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

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: job, 2: n, 3: a, 4: lda, 5: b, 6: ldb, 7: ilo, 8: ihi, 9: lscale, 10: rscale, 11: work, 12: 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.

## Accuracy

The errors are negligible, compared to those in subsequent computations.

nag_lapack_zggbal (f08wv) is usually the first step in computing the complex generalized eigenvalue problem but it is an optional step. The matrix B$B$ is reduced to the triangular form using the QR$QR$ factorization function nag_lapack_zgeqrf (f08as) and the unitary transformation Q$Q$ is applied to the matrix A$A$ by calling nag_lapack_zunmqr (f08au). This is followed by nag_lapack_zgghrd (f08ws) which reduces the matrix pair into the generalized Hessenberg form.
If the matrix pair (A,B)$\left(A,B\right)$ is balanced by this function, 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, nag_lapack_zggbak (f08ww) must be called.
The total number of floating point operations is approximately proportional to n2${n}^{2}$.
The real analogue of this function is nag_lapack_dggbal (f08wh).

## Example

```function nag_lapack_zggbal_example
job = 'B';
a = [ 1 + 3i,  1 + 4i,  1 + 5i,  1 + 6i;
2 + 2i,  4 + 3i,  8 + 4i,  16 + 5i;
3 + 1i,  9 + 2i,  27 + 3i,  81 + 4i;
4 + 0i,  16 + 1i,  64 + 2i,  256 + 3i];
b = [1,  2 + 1i,  3 + 2i,  4 + 3i;
1 + 1i,  4 + 2i,  9 + 3i,  16 + 4i;
1 + 2i,  8 + 3i,  27 + 4i,  64 + 5i;
1 + 3i,  16 + 4i,  81 + 5i,  256 + 6i];
[aOut, bOut, ilo, ihi, lscale, rscale, info] = nag_lapack_zggbal(job, a, b)
```
```

aOut =

1.0000 + 3.0000i   1.0000 + 4.0000i   0.1000 + 0.5000i   0.1000 + 0.6000i
2.0000 + 2.0000i   4.0000 + 3.0000i   0.8000 + 0.4000i   1.6000 + 0.5000i
0.3000 + 0.1000i   0.9000 + 0.2000i   0.2700 + 0.0300i   0.8100 + 0.0400i
0.4000 + 0.0000i   1.6000 + 0.1000i   0.6400 + 0.0200i   2.5600 + 0.0300i

bOut =

1.0000 + 0.0000i   2.0000 + 1.0000i   0.3000 + 0.2000i   0.4000 + 0.3000i
1.0000 + 1.0000i   4.0000 + 2.0000i   0.9000 + 0.3000i   1.6000 + 0.4000i
0.1000 + 0.2000i   0.8000 + 0.3000i   0.2700 + 0.0400i   0.6400 + 0.0500i
0.1000 + 0.3000i   1.6000 + 0.4000i   0.8100 + 0.0500i   2.5600 + 0.0600i

ilo =

1

ihi =

4

lscale =

1.0000
1.0000
0.1000
0.1000

rscale =

1.0000
1.0000
0.1000
0.1000

info =

0

```
```function f08wv_example
job = 'B';
a = [ 1 + 3i,  1 + 4i,  1 + 5i,  1 + 6i;
2 + 2i,  4 + 3i,  8 + 4i,  16 + 5i;
3 + 1i,  9 + 2i,  27 + 3i,  81 + 4i;
4 + 0i,  16 + 1i,  64 + 2i,  256 + 3i];
b = [1,  2 + 1i,  3 + 2i,  4 + 3i;
1 + 1i,  4 + 2i,  9 + 3i,  16 + 4i;
1 + 2i,  8 + 3i,  27 + 4i,  64 + 5i;
1 + 3i,  16 + 4i,  81 + 5i,  256 + 6i];
[aOut, bOut, ilo, ihi, lscale, rscale, info] = f08wv(job, a, b)
```
```

aOut =

1.0000 + 3.0000i   1.0000 + 4.0000i   0.1000 + 0.5000i   0.1000 + 0.6000i
2.0000 + 2.0000i   4.0000 + 3.0000i   0.8000 + 0.4000i   1.6000 + 0.5000i
0.3000 + 0.1000i   0.9000 + 0.2000i   0.2700 + 0.0300i   0.8100 + 0.0400i
0.4000 + 0.0000i   1.6000 + 0.1000i   0.6400 + 0.0200i   2.5600 + 0.0300i

bOut =

1.0000 + 0.0000i   2.0000 + 1.0000i   0.3000 + 0.2000i   0.4000 + 0.3000i
1.0000 + 1.0000i   4.0000 + 2.0000i   0.9000 + 0.3000i   1.6000 + 0.4000i
0.1000 + 0.2000i   0.8000 + 0.3000i   0.2700 + 0.0400i   0.6400 + 0.0500i
0.1000 + 0.3000i   1.6000 + 0.4000i   0.8100 + 0.0500i   2.5600 + 0.0600i

ilo =

1

ihi =

4

lscale =

1.0000
1.0000
0.1000
0.1000

rscale =

1.0000
1.0000
0.1000
0.1000

info =

0

```

Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013