f08nhf balances a real 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.
The errors are negligible.
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
f08nhf, then any eigenvectors computed subsequently are eigenvectors of the matrix
${A}^{\prime \prime}$ (see
Section 3) and hence
f08njf
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 orthogonal. 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
f08njf must be called (with
${\mathbf{side}}=\text{'R'}$)
to transform them back to Schur vectors of
$A$.
The complex analogue of this routine is
f08nvf.
This example computes all the eigenvalues and right eigenvectors of the matrix
$A$, where
The program first calls
f08nhf 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
f08qkf to compute the right eigenvectors of the balanced matrix, and finally calls
f08njf to transform the eigenvectors back to eigenvectors of the original matrix
$A$.