home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------//
-
- // Synopsis: Dot plot of a pseudospectrum.
-
- // Syntax: ps (A, M, TOL, RL)
-
- // Description:
-
- // Plots an approximation to a pseudospectrum of the square
- // matrix A, using M random perturbations of size TOL.
-
- // M defaults to a SIZE(A)-dependent value and TOL to 1E-3.
-
- // RL defines the type of perturbation:
- // RL = 0 (default): absolute complex perturbations of 2-norm TOL.
- // RL = 1: absolute real perturbations of 2-norm TOL.
- // RL = -1: componentwise real perturbations of size TOL.
-
- // The eigenvalues of A are plotted as symbols.
-
- // ps (A, M, TOL, RL, MARKER) creates a plot if MARKER is >= to
- // 0. If MARKER is < 0, the no plot is created, but the plot data
- // is returned.
-
- // ps (A, 0) plots just the eigenvalues of A.
-
- // For a given TOL, the pseudospectrum of A is the set of
- // pseudo-eigenvalues of A, that is, the set { e : e is an
- // eigenvalue of A+E, for some E with NORM(E) <= TOL }.
- //
- // Reference:
- // L.N. Trefethen, Pseudospectra of matrices, in D.F. Griffiths and
- // G.A. Watson, eds, Numerical Analysis 1991, Proceedings of the 14th
- // Dundee Conference, vol. 260, Pitman Research Notes in Mathematics,
- // Longman Scientific and Technical, Essex, UK, 1992, pp. 234-266.
-
- // This file is a translation of ps.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 cpltaxes
-
- //-------------------------------------------------------------------//
-
- ps = function (A, m, tol, rl, marksize)
- {
- local (A, m, tol, rl, marksize)
-
- if (diff (size (A))) { error ("Matrix must be square."); }
- n = max (size (A));
-
- if (!exist (marksize)) { marksize = 0; }
- if (!exist (rl)) { rl = 0; }
- if (!exist (tol)) { tol = 1e-3; }
- if (!exist (m)) { m = max(1, round( 25*exp(-0.047*n) )); }
-
- if (m == 0)
- {
- e = eig (A).val.';
- ax = cpltaxes (e);
- plimits (ax[1], ax[2], ax[3], ax[4]);
- plstyle ("point"); plegend ();
- plaspect (1); plaxis ();
- plot ([ real (e), imag (e) ]);
- return 1;
- }
-
- x = zeros (m*n,1);
- i = sqrt (-1);
-
- for (j in 1:m)
- {
- if (rl == -1)
- {
- // Componentwise.
- rand ("uniform", -1, 1);
- dA = -ones(n) + 2*rand(n,n); // Uniform random numbers on [-1,1].
- dA = tol * A .* dA;
- else
- rand ("normal", 0, 1);
- if (rl == 0)
- {
- // Complex absolute.
- dA = rand (n,n) + i*rand (n,n);
- else
- // Real absolute.
- dA = rand (n,n);
- }
- dA = tol/norm (dA)*dA;
- }
- e = eig(A + dA).val.';
- x[(j-1)*n+1:j*n] = e;
- }
-
- if (marksize >= 0)
- {
- ax = cpltaxes(x);
- plimits (ax[1], ax[2], ax[3], ax[4]);
- plstyle ("point"); plegend ();
- plaspect (1); plaxis ();
- plot ([ real(x), imag(x)] );
-
- e = eig(A).val.';
- subplot (0);
- plot ([ real (e), imag (e) ]);
-
- return x;
-
- else
-
- return x;
-
- }
- };
-