Mercurial > matrix-functions
comparison matrixcomp/gersh.m @ 0:8f23314345f4 draft
Create local repository for matrix toolboxes. Step #0 done.
author | Antonio Pino Robles <data.script93@gmail.com> |
---|---|
date | Wed, 06 May 2015 14:56:53 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8f23314345f4 |
---|---|
1 function [G, e] = gersh(A, noplot) | |
2 %GERSH Gershgorin disks. | |
3 % GERSH(A) draws the Gershgorin disks for the square 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(GALLERY('LESP',N)) and GERSH(GALLERY('SMOKE',N)). | |
9 | |
10 if diff(size(A)), error('Matrix must be square.'), end | |
11 | |
12 n = length(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 * linspace(0,2*pi,m)'); | |
21 | |
22 for j=1:n | |
23 G(:,j) = d(j)*ones(m,1) + 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)),'-') % Plot the disks. | |
31 hold on | |
32 end | |
33 plot(real(e), imag(e), 'x') % Plot the eigenvalues too. | |
34 axis(ax) | |
35 axis('square') | |
36 hold off | |
37 | |
38 end |