hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_lapack_dgebal (f08nh)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_lapack_dgebal (f08nh) balances a real general matrix in order to improve the accuracy of computed eigenvalues and/or eigenvectors.


[a, ilo, ihi, scale, info] = f08nh(job, a, 'n', n)
[a, ilo, ihi, scale, info] = nag_lapack_dgebal(job, a, 'n', n)


nag_lapack_dgebal (f08nh) balances a real 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


Compulsory Input Parameters

1:     job – string (length ≥ 1)
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='N', 'P', 'S' or 'B'.
2:     alda: – double array
The first dimension of the array a must be at least max1,n.
The second dimension of the array a must be at least max1,n.
The n by n matrix A.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the first dimension of the array a and the second dimension of the array a.
n, the order of the matrix A.
Constraint: n0.

Output Parameters

1:     alda: – double array
The first dimension of the array a will be max1,n.
The second dimension of the array a will be max1,n.
a stores the balanced matrix. If job='N', a is not referenced.
2:     ilo int64int32nag_int scalar
3:     ihi int64int32nag_int scalar
The values ilo and ihi such that on exit aij is zero if i>j and 1j<ilo or ihi<in.
If job='N' or 'S', ilo=1 and ihi=n.
4:     scalen – double array
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
scalej = 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.
5:     info int64int32nag_int scalar
info=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

If info=-i, parameter i had an illegal value on entry. The parameters are numbered as follows:
1: job, 2: n, 3: a, 4: lda, 5: ilo, 6: ihi, 7: scale, 8: 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.


The errors are negligible.

Further Comments

If the matrix A is balanced by nag_lapack_dgebal (f08nh), then any eigenvectors computed subsequently are eigenvectors of the matrix A (see Description) and hence nag_lapack_dgebak (f08nj) 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='S' or 'B', because then the balancing transformation is not orthogonal. If this function is called with job='P', then any Schur vectors computed subsequently are Schur vectors of the matrix A, and nag_lapack_dgebak (f08nj) must be called (with side='R') to transform them back to Schur vectors of A.
The total number of floating-point operations is approximately proportional to n2.
The complex analogue of this function is nag_lapack_zgebal (f08nv).


This example computes all the eigenvalues and right eigenvectors of the matrix A, where
A = 5.14 0.91 0.00 -32.80 0.91 0.20 0.00 34.50 1.90 0.80 -0.40 -3.00 -0.33 0.35 0.00 0.66 .  
The program first calls nag_lapack_dgebal (f08nh) 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_lapack_dtrevc (f08qk) to compute the right eigenvectors of the balanced matrix, and finally calls nag_lapack_dgebak (f08nj) to transform the eigenvectors back to eigenvectors of the original matrix A.
function f08nh_example

fprintf('f08nh example results\n\n');

n = int64(4);
a = [ 5.14, 0.91,  0.00, -32.80;
      0.91, 0.20,  0.00,  34.50;
      1.90, 0.80, -0.40,  -3.00;
     -0.33, 0.35,  0.00,   0.66];

% Balance a
[a, ilo, ihi, scale, info] = f08nh( ...
                                    'Both', a);

% Reduce a to upper Hessenberg form
[H, tau, info] = f08ne( ...
                        ilo, ihi, a);

% Form Q
[Q, info] = f08nf( ...
                   ilo, ihi, H, tau);

% Calculate the eigenvalues and Schur factorisation of A
[H, wr, wi, Z, info] = f08pe( ...
                              'Schur Form', 'Vectors', ilo, ihi, H, Q);

w = wr + i*wi;

% Calculate the eigenvectors of A
[select, ~, VR, m, info] = ...
f08qk( ...
       'Right', 'Backtransform', false, H, zeros(1), Z, n);

% Back scale to get eigenvectors of A
[VR, info] = f08nj( ...
                    'Both', 'Right', ilo, ihi, scale, VR);

% Normalize eigenvectors: largest element positive
for j = 1:n
  [~,k] = max(abs(VR(:,j)));
  VR(:,j) =VR(:,j)/norm(VR(:,j));
  if VR(k,j) < 0;
    VR(:,j) = -VR(:,j);


f08nh example results


         0   -0.4381    0.4654    0.9513
         0    0.8923    0.7888   -0.1714
    1.0000   -0.0481    0.3981    0.2494
         0   -0.0976    0.0521   -0.0589

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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