NAG Library Function Document

nag_zgebal (f08nvc)


    1  Purpose
    7  Accuracy


nag_zgebal (f08nvc) balances a complex general matrix in order to improve the accuracy of computed eigenvalues and/or eigenvectors.


#include <nag.h>
#include <nagf08.h>
void  nag_zgebal (Nag_OrderType order, Nag_JobType job, Integer n, Complex a[], Integer pda, Integer *ilo, Integer *ihi, double scale[], NagError *fail)


nag_zgebal (f08nvc) balances a complex general matrix A. The term ‘balancing’ covers two steps, each of which involves a similarity transformation of A. The function can perform either or both of these steps.
1. The function first attempts to permute A to block upper triangular form by a similarity transformation:
PAPT = A = A11 A12 A13 0 A22 A23 0 0 A33  
where P is a permutation matrix, and A11 and A33 are upper triangular. Then the diagonal elements of A11 and A33 are eigenvalues of A. The rest of the eigenvalues of A are the eigenvalues of the central diagonal block A22, in rows and columns ilo to ihi. 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 ilo>1 and ihi<n. If no suitable permutation exists (as is often the case), the function sets ilo=1 and ihi=n, and A22 is the whole of A.
2. The function applies a diagonal similarity transformation to A, to make the rows and columns of A22 as close in norm as possible:
A = DAD-1 = I 0 0 0 D22 0 0 0 I A11 A12 A13 0 A22 A23 0 0 A33 I 0 0 0 D22-1 0 0 0 I .  
This scaling can reduce the norm of the matrix (i.e., A22<A22) and hence reduce the effect of rounding errors on the accuracy of computed eigenvalues and eigenvectors.


Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore


1:     order Nag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by order=Nag_RowMajor. See Section in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2:     job Nag_JobTypeInput
On entry: indicates whether A is to be permuted and/or scaled (or neither).
A is neither permuted nor scaled (but values are assigned to ilo, ihi and scale).
A is permuted but not scaled.
A is scaled but not permuted.
A is both permuted and scaled.
Constraint: job=Nag_DoNothing, Nag_Permute, Nag_Scale or Nag_DoBoth.
3:     n IntegerInput
On entry: n, the order of the matrix A.
Constraint: n0.
4:     a[dim] ComplexInput/Output
Note: the dimension, dim, of the array a must be at least max1,pda×n.
Where Ai,j appears in this document, it refers to the array element
  • a[j-1×pda+i-1] when order=Nag_ColMajor;
  • a[i-1×pda+j-1] when order=Nag_RowMajor.
On entry: the n by n matrix A.
On exit: a is overwritten by the balanced matrix. If job=Nag_DoNothing, a is not referenced.
5:     pda IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array a.
Constraint: pdamax1,n.
6:     ilo Integer *Output
7:     ihi Integer *Output
On exit: the values ilo and ihi such that on exit Ai,j is zero if i>j and 1j<ilo or ihi<in.
If job=Nag_DoNothing or Nag_Scale, ilo=1 and ihi=n.
8:     scale[n] doubleOutput
On exit: details of the permutations and scaling factors applied to A. More precisely, if pj is the index of the row and column interchanged with row and column j and dj is the scaling factor used to balance row and column j then
scale[j-1] = pj, j=1,2,,ilo-1 dj, j=ilo,ilo+1,,ihi  and pj, j=ihi+1,ihi+2,,n.  
The order in which the interchanges are made is n to ihi+1 then 1 to ilo-1.
9:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

Dynamic memory allocation failed.
See Section in How to Use the NAG Library and its Documentation for further information.
On entry, argument value had an illegal value.
On entry, n=value.
Constraint: n0.
On entry, pda=value.
Constraint: pda>0.
On entry, pda=value and n=value.
Constraint: pdamax1,n.
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.


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

Parallelism and Performance

nag_zgebal (f08nvc) 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

Further Comments

If the matrix A is balanced by nag_zgebal (f08nvc), then any eigenvectors computed subsequently are eigenvectors of the matrix A (see Section 3) and hence nag_zgebak (f08nwc) must then be called to transform them back to eigenvectors of A.
If the Schur vectors of A are required, then this function must not be called with job=Nag_Scale or Nag_DoBoth, because then the balancing transformation is not unitary. If this function is called with job=Nag_Permute, then any Schur vectors computed subsequently are Schur vectors of the matrix A, and nag_zgebak (f08nwc) must be called (with side=Nag_RightSide) to transform them back to Schur vectors of A.
The total number of real floating-point operations is approximately proportional to n2.
The real analogue of this function is nag_dgebal (f08nhc).


This example computes all the eigenvalues and right eigenvectors of the matrix A, where
A = 1.50-2.75i 0.00+0.00i 0.00+0.00i 0.00+0.00i -8.06-1.24i -2.50-0.50i 0.00+0.00i -0.75+0.50i -2.09+7.56i 1.39+3.97i -1.25+0.75i -4.82-5.67i 6.18+9.79i -0.92-0.62i 0.00+0.00i -2.50-0.50i .  
The program first calls nag_zgebal (f08nvc) 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 nag_ztrevc (f08qxc) to compute the right eigenvectors of the balanced matrix, and finally calls nag_zgebak (f08nwc) to transform the eigenvectors back to eigenvectors of the original matrix A.

Program Text

Program Text (f08nvce.c)

Program Data

Program Data (f08nvce.d)

Program Results

Program Results (f08nvce.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017