home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------//
-
- // Synopsis: Field of values (or numerical range)
-
- // Syntax: fv (A, NK, THMAX)
-
- // Description:
-
- // fv evaluates and plots the field of values of the NK largest
- // leading principal submatrices of A, using THMAX equally spaced
- // angles in the complex plane. The defaults are NK = 1 and
- // THMAX = 16. (For a `publication quality' picture, set THMAX
- // higher, say 32.) The eigenvalues of A are displayed as `x'.
-
- // Alternative usage: fv(A, NK, THMAX, 1) suppresses the plot and
- // returns the field of values plot data and A's eigenvalues in a
- // list. Note that norm(F,"i") approximates the numerical radius,
-
- // max {abs(z): z is in the field of values of A}.
-
- // Theory:
-
- // Field of values fv(A) = set of all Rayleigh quotients. fv(A)
- // is a convex set containing the eigenvalues of A. When A is
- // normal fv(A) is the convex hull of the eigenvalues of A (but
- // not vice versa).
-
- // z = x'Ax/(x'x), z' = x'A'x/(x'x)
- // => real(z) = x'Hx/(x'x), H = (A+A')/2
- // so min(eig(H)) <= real(z) <= max(eig(H))
-
- // with equality for x = corresponding eigenvectors of H. For
- // these x, rq(A,x) is on the boundary of fv(A).
-
- // Based on an original routine by A. Ruhe.
- //
- // References:
- // R.A. Horn and C.R. Johnson, Topics in Matrix Analysis, Cambridge
- // University Press, 1991, Section 1.5.
- // A.S. Householder, The Theory of Matrices in Numerical Analysis,
- // Blaisdell, New York, 1964, Section 3.3.
- // C.R. Johnson, Numerical determination of the field of values of a
- // general complex matrix, SIAM J. Numer. Anal., 15 (1978),
- // pp. 595-602.
-
- // This file is a translation of fv.m from version 2.0 of
- // "The Test Matrix Toolbox for Matlab", described in Numerical
- // Analysis Report No. 237, December 1993, by N. J. Higham.
-
- // Dependencies
- require rq symmpart skewpart cpltaxes
-
- //-------------------------------------------------------------------//
-
- fv = function (B, nk, thmax, noplot)
- {
- local (B, nk, thmax, noplot)
- global (pi)
-
- if (!exist (nk)) { nk = 1; }
- if (!exist (thmax)) { thmax = 16; }
-
- // Because code below uses thmax + 1 angles.
- thmax = thmax - 1;
-
- iu = sqrt(-1);
- n = B.nr;
- p = B.nc;
- if (n != p) { error("Matrix must be square."); }
- f = [];
- z = zeros(2*thmax+1,1);
- e = eig(B).val;
-
- // Filter out cases where B is Hermitian or skew-Hermitian, for efficiency.
-
- if (norm(skewpart(B)) == 0)
- {
- f = [min(e), max(e)];
- else if (norm(symmpart(B)) == 0) {
- e = imag(e);
- f = [min(e), max(e)];
- e = iu*e;
- f = iu*f;
- else
- for (m in 1:nk)
- {
- ns = n+1-m;
- A = B[1:ns; 1:ns];
- for (i in 0:thmax)
- {
- th = i/thmax*pi;
- Ath = exp(iu*th)*A; // Rotate A through angle th.
- H = 0.5*(Ath + Ath'); // Hermitian part of rotated A.
- XD = eig(H);
- k = sort(real(XD.val)).ind;
- z[1+i] = rq(A, XD.vec[;k[1]]); // RQ's of A corr. to eigenvalues of H
- z[1+i+thmax] = rq(A,XD.vec[;k[ns]]); // with smallest/largest real part.
- }
- f = [f; z];
- }
-
- // Next line ensures boundary is `joined up' (needed for orthogonal matrices).
-
- f = [f; f[1;]];
-
- } }
-
- if (thmax == 0) { f = e; }
-
- if (!exist (noplot))
- {
- ax = cpltaxes(f);
- plaspect (1);
- plegend ();
- plimits (ax[1], ax[2], ax[3], ax[4]);
- plstyle ("line-point");
- plaxis ();
- plot([real(f), imag(f)]); // Plot the field of values
- subplot(0);
- plstyle ("point");
- plot([real(e)', imag(e)']); // Plot the eigenvalues too.
- }
-
- return << f=f ; e=e >>;
- };
-