nag_lapack_dgebal (f08nh) balances a real general matrix
. The term ‘balancing’ covers two steps, each of which involves a similarity transformation of
. The function can perform either or both of these steps.
1. |
The function first attempts to permute to block upper triangular form by a similarity transformation:
where is a permutation matrix, and and are upper triangular. Then the diagonal elements of and are eigenvalues of . The rest of the eigenvalues of are the eigenvalues of the central diagonal block , in rows and columns to . Subsequent operations to compute the eigenvalues of (or its Schur factorization) need only be applied to these rows and columns; this can save a significant amount of work if and . If no suitable permutation exists (as is often the case), the function sets and , and is the whole of . |
2. |
The function applies a diagonal similarity transformation to , to make the rows and columns of as close in norm as possible:
This scaling can reduce the norm of the matrix (i.e., ) and hence reduce the effect of rounding errors on the accuracy of computed eigenvalues and eigenvectors. |
The errors are negligible.
If the matrix
is balanced by
nag_lapack_dgebal (f08nh), then any eigenvectors computed subsequently are eigenvectors of the matrix
(see
Description) and hence
nag_lapack_dgebak (f08nj)
must then be called to transform them back to eigenvectors of
.
If the Schur vectors of
are required, then this function must
not be called with
or
, because then the balancing transformation is not orthogonal. If this function is called with
, then any Schur vectors computed subsequently are Schur vectors of the matrix
, and
nag_lapack_dgebak (f08nj) must be called (with
)
to transform them back to Schur vectors of
.
The complex analogue of this function is
nag_lapack_zgebal (f08nv).
This example computes all the eigenvalues and right eigenvectors of the matrix
, where
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
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
.
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];
[a, ilo, ihi, scale, info] = f08nh( ...
'Both', a);
[H, tau, info] = f08ne( ...
ilo, ihi, a);
[Q, info] = f08nf( ...
ilo, ihi, H, tau);
[H, wr, wi, Z, info] = f08pe( ...
'Schur Form', 'Vectors', ilo, ihi, H, Q);
w = wr + i*wi;
disp('Eigenvalues:');
disp(w);
[select, ~, VR, m, info] = ...
f08qk( ...
'Right', 'Backtransform', false, H, zeros(1), Z, n);
[VR, info] = f08nj( ...
'Both', 'Right', ilo, ihi, scale, VR);
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);
end
end
disp('Eigenvectors:');
disp(VR);