5.2. Large Experiment with Randomly Generated Examples
In a run with 4,188,166 random examples, the first three examples had , , and . Specifically, all examples were generated using the following MATLAB commands, where a1 and a2 are used for and , respectively.
a1 = randn + 1i*randn; a2 = 0;
a2 = a1; a1 = 0;
a2 = 0;
for ii = -1022 : 1023
s1 = 2^ii; re = s1*randn; im = s1*randn;
if abs( re ) > realmax, re = sign( re )*realmax; end
if abs( im ) > realmax, im = sign( im )*realmax; end
a1 = re + 1i*im;
for jj = -1022 : 1023
s2 = 2^jj; re = s2*randn; im = s2*randn;
if abs( re ) > realmax, re = sign( re )*realmax; end
if abs( im ) > realmax, im = sign( im )*realmax; end
a2 = re + 1i*im;
end
end
s1 = realmax; re = s1*randn; im = s1*randn;
if abs( re ) > realmax, re = sign( re )*realmax; end
if abs( im ) > realmax, im = sign( im )*realmax; end
a1 = re + 1i*im;
for jj = -1022 : 1023
s2 = 2^jj; re = s2*randn; im = s2*randn;
if abs( re ) > realmax, re = sign( re )*realmax; end
if abs( im ) > realmax, im = sign( im )*realmax; end
a2 = re + 1i*im;
end
s2 = realmax; re = s2*randn; im = s2*randn;
if abs( re ) > realmax, re = sign( re )*realmax; end
if abs( im ) > realmax, im = sign( im )*realmax; end
a2 = re + 1i*im;
The for loop with counter ii generates numbers s1 between (realmin) and 8.988465674311580e+307, which is very close to, but smaller than , (realmax), the relative error being smaller than 5.552e-17. The number s1 multiplies pseudorandom double precision values drawn from the standard normal distribution (with mean 0 and standard deviation 1), to obtain the real and imaginary parts of . If any of the computed parts of exceed K in magnitude, i.e., if is obtained, that value is reset to . The number is obtained in the same way in the internal loop with counter jj. The second part of the code segment has and it is used to obtain ; is generated as above. The last part also sets , and uses it to obtain . Clearly, complex numbers with and/or are generated.
For reproducibility of the results, the command sequence above was run after the MATLAB statement
which ensures that the (initial) seed of the random number generator is the same, and therefore the same sequence of random numbers is generated after using this command. However, for some further tests, the generating sequence was run repeatedly several times, but the rng( ’default’ ) command was placed just before the first run. This way, a larger number of tests were performed.
After each of the first three MATLAB commands, inside the (internal) loops, and after the last command, an implementation of Algorithm
chordal is called, and its results are compared with those obtained using a MATLAB command for (
1), but also a more sophisticated MATLAB code based on algorithms described in
Section 4. This is needed since using (
1) directly might return inaccurate results, as shown in
Section 5.1.
The maximum relative error in this run was
6.3088e-16; the relative error is defined as
, where
d and
denote the results obtained by evaluating (
1) in MATLAB and by using an implementation of Algorithm
chordal, respectively. Note that with another definition,
, if
, and
, otherwise, its maximum value was
0.2649. However, the value became zero when using the modified MATLAB code, based on algorithms described in the previous section. After ten consecutive runs (without reinitialization of the random number generator between runs), the maximum relative error and its mean value were
7.6144e-16 and
6.3663e-16, respectively, while using the second definition, the values were
0.73077 and
0.35080, and they became zero with the modified MATLAB code.
In this test sequence, there were 3,970,109 examples with or negligible compared to the other; hence, the logical variable f in Algorithm chordal was true. This represents 94.794% from the total number of examples. Specifically, 1,985,994 and 1,984,115 examples have and , respectively. From those with , 987,937 have , 994,601 have , and 3456 have . From examples with , 987,834 have , 992,853 have , and 3428 have . These categories correspond to the three cases, with , , and , respectively. For , the logical variables and , , were true for all examples satisfying and , respectively. Moreover, for examples satisfying , when as well as needed to be computed, both and were true. Using a factored representation has never been necessary for any of these 3,970,109 examples.
A summary of the number of examples needing only to compute
and/or
is presented in
Table 1.
For the remaining 218,055 examples, representing 5.206% of all examples,
and
are nonzero, distinct and relatively “close” to each other, since
. All these examples needed both
and
values to compute
and
. A factored representation for
was required for 56 examples. Although 21 examples were expected to require a factored representation for
, the factors could be multiplied without overflows for nine of these examples.
Table 2 summarizes the number of examples with and without a factored representation for
and
.
To get (also denoted in the pseudocodes), Algorithm subtract was used to obtain the real and imaginary parts, and , of . For three and two examples, and , respectively, would exceed K in magnitude. For the other 218,050 examples, was evaluated using Algorithm absa, and could be obtained from via Algorithm d2byd1. Specifically, was true on input to absa for 217,980 examples, and it was false for the remaining 70 examples with expected overflow; but for 12 out of 70 examples, was reset to true, since ; therefore, needed the factored representation defined by and for only 58 examples. Moreover, 107,475 out of the 218,050 examples satisfied the conditions and , which implies that ; hence, , and was not needed. For the remaining 110,575 examples, , with evaluated using (or and ), (or and ) and (or and ). Specifically, for the four cases with in Algorithm d2byd1 ( and , and , and , and ), there were 110,514, zero, two, and one examples, respectively. Similarly, for the four cases with , there were zero, six, 51, and one examples, respectively.
Clearly, for the five examples for which could not be computed, ; hence, was evaluated by calling twice Algorithm inva (for and ) and Algorithm subtract (for the real and imaginary parts of ). The logical variables and were true for four and one examples, respectively, and false for one and four examples. Therefore, all formulas for and in Algorithm inva were applied. Then, was obtained using Algorithm subtract separately for the real and imaginary parts of ; the variable remained true for each of these examples. The result was found by Algorithm absa.
A summary of the number of examples needing to compute
and/or
is presented in
Table 3.
Table 4 shows the number of examples with/without a factored representation for
and
. Note that
is always representable.
The results presented and summarized in the tables show that all examples were solved using the simplest possible formulas, which proves the efficiency of the implementation. Moreover, it was checked that the results were practically the same with those obtained when
was always computed using (
6).
This demonstrates that the accuracy was preserved using the simplified formulas.
5.3. Application: Block Diagonalization of Matrix Pencils
This subsection presents the results obtained for block diagonalization of matrix pencils. The approximate symmetric chordal metric is used to measure the “distances” between eigenvalues, and based on this, to reorder and group them in clusters for reducing the condition numbers of the transformation matrices involved in the process.
Two examples with different levels of difficulty are described.
A random example. A matrix pencil of order was generated using normally distributed pseudorandom numbers produced by the following MATLAB commands:
rng( ’default’ ); n = 100;
A = randn( n ); B = randn( n );
p = 10^3*rand( n, 1 ); q = rand( n, 1 )/10^2;
P = diag( p ); Q = diag( q ); A = P*A*Q; B = P*B*Q;
The vectors
p and
q, drawn from a uniform distribution, are used to scale the rows and columns, respectively, of
A and
B. The spectrum of the scaled matrix pencil
is shown in
Figure 1.
The Euclidean norms of
A and
B and the ranges of their elements are listed in
Table 5. The values are rounded to five significant digits.
A MATLAB-executable, developed by the author, was used to perform the block diagonalization of the scaled matrix pencil
. The executable has an option to work on general matrices, or on matrices already reduced to the generalized Schur form [
17],
, with
,
, where
Q and
Z are orthogonal (hence,
and
, with
the identity matrix of order
n);
is upper triangular, and
is block upper triangular with diagonal blocks of order 1 or 2, corresponding to real or complex conjugate eigenvalues, respectively. (All elements under the diagonal of
and under the diagonal blocks of
are zero.) The block diagonalization algorithm acts on
and
. An essential part of the computations is the solution of a generalized Sylvester equation. Since this involves non-unitary transformations, their elements should be bounded, to ensure good accuracy. Specifically, if any of these elements exceeds a given threshold
, the process is stopped, and solving an enlarged Sylvester equation is tried. If many failed attempts are involved, the computational effort might be unacceptably high. Using the bound
and default options (the diagonal blocks are not reordered before each reduction step, the left and right transformations are updated), the algorithm computed the transformed matrix pencil
, with
,
,
,
, where
and
are the global transformations applied to
and
by the block diagonalization algorithm. The reduced matrix
is block diagonal (see
Figure 2), with diagonal blocks of order 1 and 2, while matrix
is diagonal. There are 14 block pairs of order 1 and 43 block pairs of order 2. Since the original pencil has 14 real eigenvalues, the maximal possible reduction (with real arithmetic) was obtained.
Let
and
be the absolute errors of
and
with respect to the transformed matrices
and
, respectively, and let
and
be their relative errors, i.e.,
,
, with
the Euclidean norm. Similarly, let
and
be the absolute and relative errors of the eigenvalues
of the matrix pencil
with respect to the eigenvalues
of the matrix pencil
. If the eigenvalue problem is well conditioned, then
are very close to the true eigenvalues
of the matrix pencil
. These errors are reported in
Table 6.
All these errors are as good as possible for such a problem, which shows that the block diagonalization was successful. The reduced matrix pencil can be used efficiently instead of the original pencil, e.g., for computing matrix functions or the responses of a linear descriptor system. In this case, the input and output matrices of the system should be updated with the computed transformation matrices and .
An example with dense clusters of eigenvalues. A matrix pencil of order
with many clustered eigenvalues is considered now. The matrices
A and
B are already reduced to the generalized real Schur form. The spectrum is shown in
Figure 3. It has 107 real and 446 complex conjugate eigenvalues.
The Euclidean norms of
A and
B and the ranges of their elements are listed in
Table 7. The values are rounded to five significant digits.
Using the approach described for the randomly generated example, a solution with 135 diagonal block pairs was computed in 62.68s (seconds). The largest block pair, of order 734, appeared in the 89-th block position on the diagonals; in addition, there are three and 131 2 × 2 diagonal block pairs. The remaining 104 real eigenvalues are included in the largest block pair.
Using an eigenvalue reordering strategy based on the pairwise “distances” between eigenvalues, measured by the approximate symmetric chordal metric, another solution was computed in 4.6905s; hence, the execution time was 13.36 times shorter. Specifically, 763 selected eigenvalues were moved to the leading positions, obtaining the matrices
and
. The needed transformation matrices,
and
, were computed. This reordering process, including the computation of
and
, needed 2.4826s. The block diagonalization was then applied to the matrices
and
, and it took 2.2078s. The relative errors in the transformed matrices and eigenvalues for the two computational stages are shown in
Table 8.
Compared to the first approach, more block pairs, namely, 141, were found and the largest block pair, of order 719, appeared in the last position. This is the preferred situation, since well-separated eigenvalues could be quickly placed in small block pairs in the leading part, while big clusters remain to be placed in the trailing part of the matrix pencil. There were 140 2 × 2 block pairs; so, all real eigenvalues were available in the largest block pair. The efficiency gain is mainly due to better eigenvalue reordering, which reduced the number of failed attempts to solve the generalized Lyapunov equations. However, it is worth noting that the number of “distances” between eigenvalues is ; hence, it increases quadratically with the problem size. Therefore, it is important that the algorithms for computing the approximate symmetric chordal metric are as fast as possible.
The computed matrix has 140 diagonal blocks followed by a diagonal block. The matrix is diagonal with positive diagonal elements.