Mercurial > matrix-functions
comparison toolbox/gersh.m @ 2:c124219d7bfa draft
Re-add the 1995 toolbox after noticing the statement in the ~higham/mctoolbox/ webpage.
author | Antonio Pino Robles <data.script93@gmail.com> |
---|---|
date | Thu, 07 May 2015 18:36:24 +0200 |
parents | 8f23314345f4 |
children |
comparison
equal
deleted
inserted
replaced
1:e471a92d17be | 2:c124219d7bfa |
---|---|
1 function [G, e] = gersh(A, noplot) | |
2 %GERSH Gershgorin disks. | |
3 % GERSH(A) draws the Gershgorin disks for the matrix A. | |
4 % The eigenvalues are plotted as crosses `x'. | |
5 % Alternative usage: [G, E] = GERSH(A, 1) suppresses the plot | |
6 % and returns the data in G, with A's eigenvalues in E. | |
7 % | |
8 % Try GERSH(LESP(N)) and GERSH(SMOKE(N,1)). | |
9 | |
10 if diff(size(A)), error('Matrix must be square.'), end | |
11 | |
12 n = max(size(A)); | |
13 m = 40; | |
14 G = zeros(m,n); | |
15 | |
16 d = diag(A); | |
17 r = sum( abs( A.'-diag(d) ) )'; | |
18 e = eig(A); | |
19 | |
20 radvec = exp(i * seqa(0,2*pi,m)'); | |
21 | |
22 for j=1:n | |
23 G(:,j) = d(j)*ones(size(radvec)) + r(j)*radvec; | |
24 end | |
25 | |
26 if nargin < 2 | |
27 | |
28 ax = cpltaxes(G(:)); | |
29 for j=1:n | |
30 plot(real(G(:,j)), imag(G(:,j)),'-c5') % Plot the disks. | |
31 hold on | |
32 end | |
33 plot(real(e), imag(e), 'xg') % Plot the eigenvalues too. | |
34 axis(ax); | |
35 axis('square'); | |
36 hold off | |
37 | |
38 end |