function gershgorin(A)
%
% Demonstration of Gershgorin's circle theorem. 
% Example: A = [1+0.5*i,   0.5,    0.1;
%                0.3,    1-0.5*i,  0.5;
%                0.5,      0.0    -0.5];
%
% The eigenvvalues are marked in red. 
%
N = length(A);
hold on
da = diag(A);
plot(real(da),imag(da),'o','MarkerFaceColor','g');

th = linspace(0,2*pi,101);
for n=1:N
    r = sum(abs(A(n,:)))-abs(da(n));
    plot(real(da(n))+r*cos(th),imag(da(n))+r*sin(th));
end
axis 'equal', grid
l = eig(A);
plot(real(l),imag(l),'o','MarkerFaceColor','r');
hold off

