# ?ggbal

Balances a pair of general real or complex matrices.

## Syntax

FORTRAN 77:

call sggbal(job, n, a, lda, b, ldb, ilo, ihi, lscale, rscale, work, info)

call dggbal(job, n, a, lda, b, ldb, ilo, ihi, lscale, rscale, work, info)

call cggbal(job, n, a, lda, b, ldb, ilo, ihi, lscale, rscale, work, info)

call zggbal(job, n, a, lda, b, ldb, ilo, ihi, lscale, rscale, work, info)

Fortran 95:

call ggbal(a, b [,ilo] [,ihi] [,lscale] [,rscale] [,job] [,info])

## Description

This routine balances a pair of general real/complex matrices (A,B). This involves, first, permuting A and B by similarity transformations to isolate eigenvalues in the first 1 to ilo-1 and last ihi+1 to n elements on the diagonal;and second, applying a diagonal similarity transformation to rows and columns ilo to ihi to make the rows and columns as close in norm as possible. Both steps are optional. Balancing may reduce the 1-norm of the matrices, and improve the accuracy of the computed eigenvalues and/or eigenvectors in the generalized eigenvalue problem `A*x = λ*B*x`.

## Input Parameters

job

  CHARACTER*1. Specifies the operations to be performed on A and B. Must be 'N' or 'P' or 'S' or 'B'.

  If `job = 'N'`, then no operations are done; simply set `ilo =1`, `ihi=n`, `lscale(i) =1.0` and `rscale(i)=1.0` for

  `i = 1,..., n`.

  If `job = 'P'`, then permute only.

  If `job = 'S'`, then scale only.

  If `job = 'B'`, then both permute and scale.

n

  INTEGER. The order of the matrices A and B (n ≥ 0).

a, b

  REAL for sggbal

  DOUBLE PRECISION for dggbal

  COMPLEX for cggbal

  DOUBLE COMPLEX for zggbal.

  Arrays:

  a(lda,*) contains the matrix A. The second dimension of a must be at least max(1, n).

  b(ldb,*) contains the matrix B. The second dimension of b must be at least max(1, n).

lda

  INTEGER. The first dimension of a; at least max(1, n).

ldb

  INTEGER. The first dimension of b; at least max(1, n).

work

  REAL for single precision flavors

  DOUBLE PRECISION for double precision flavors.

  Workspace array, DIMENSION at least `max(1, 6n)` when `job = 'S'`or `'B'`, or at least `1` when `job = 'N'`or `'P'`.

## Output Parameters

a, b

  Overwritten by the balanced matrices A and B, respectively.

  If `job = 'N'`, a and b are not referenced.

ilo, ihi

  INTEGER. ilo and ihi are set to integers such that on exit `a(i,j)=0` and `b(i,j)=0` if `i>j` and `j=1,...,ilo-1` or `i=ihi+1,..., n`.

  If `job = 'N'`or 'S', then `ilo = 1` and `ihi = n`.

lscale, rscale

  REAL for single precision flavors

  DOUBLE PRECISION for double precision flavors.

  Arrays, DIMENSION at least max(1, n).

  lscale contains details of the permutations and scaling factors applied to the left side of A and B.

  If Pj is the index of the row interchanged with row j, and Dj is the scaling factor applied to row j, then

  `lscale(j) = Pj`, for `j = 1,..., ilo-1`

  `= Dj`, for `j = ilo,...,ihi`

  `= Pj`, for `j = ihi+1,..., n`.

  rscale contains details of the permutations and scaling factors applied to the right side of A and B.

  If Pj is the index of the column interchanged with column j, and Dj is the scaling factor applied to column j, then

  `rscale(j) = Pj`, for `j = 1,..., ilo-1`

  `= Dj`, for `j = ilo,...,ihi`

  `= Pj`, for `j = ihi+1,..., n`

  The order in which the interchanges are made is n to ihi+1, then 1 to ilo-1.

info

  INTEGER.

  If `info = 0`, the execution is successful.

  If info = -i, the i-th parameter had an illegal value.

## Fortran 95 Interface Notes

Routines in Fortran 95 interface have fewer arguments in the calling sequence than their FORTRAN 77 counterparts. For general conventions applied to skip redundant or restorable arguments, see Fortran 95 Interface Conventions.

Specific details for the routine ggbal interface are the following:

a

  Holds the matrix A of size (n,n).

b

  Holds the matrix B of size (n,n).

lscale

  Holds the vector of length (n).

rscale

  Holds the vector of length (n).

ilo

  Default value for this argument is `ilo = 1`.

ihi

  Default value for this argument is `ihi = n`.

job

  Must be 'B', 'S', 'P', or 'N'. The default value is 'B'.

Parent topic: Generalized Nonsymmetric Eigenvalue Problems