1
votes

I'm trying to plot some eigenvalues along with their Gershgorin circles in matlab, but don't seem to be able to find the syntax to get the discrete points (the eigenvalues) to show up. This is what I've tried:

clear all ;

m = [ 1  -1  0  0 ;
  -1  2 -1  0 ;
  0  -1  2  1 ;
  0   0  -1 1 ]

e = eig( m ) ;

n = 30 ;
z1 = zeros( n + 1, 1 ) ;
z2 = zeros( n + 1, 1 ) ;

for i = [ 1 : n + 1 ]
   z1(i) = 2 + 2 * exp(j * 2 * pi * (i - 1)/ 30) ;
   z2(i) = 1 + exp(j * 2 * pi * (i - 1)/ 30) ;
end

h = plot( real(e(1)), imag(e(1)), real(e(2)), imag(e(2)), real(e(3)), imag(e(3)), real(e(4)), imag(e(4)), real(z1), imag(z1), real(z2), imag(z2) )

set(h(1),'LineWidth',2) ;
set(h(2),'LineWidth',2) ;
set(h(3),'LineWidth',2) ;
set(h(4),'LineWidth',2) ;

Which produces a plot in which I can see the circles, but not the points:

Gershgorin plot attempt

If I use the same set command on h(5) or h(6) it does make the circle plots show up thicker as I would have expected.

2

2 Answers

4
votes

Well it does not show up because of the call to plot to plot points (horrible sentence sorry!). It's fine if you use scatter.

I modified a bit your code, that's why this is not a comment haha.

1) I vectorized your for-loop, which is quite faster on my computer. BTW, using i as an index is risky, especially when dealing with complex numbers. The safe way to go is either use something else, or

2) use 1j or 1i to represent the imaginary unit. That's also faster.

Anyhow here is the code with the points bigger:

clear
clc
close all


m = [ 1  -1  0  0 ;
  -1  2 -1  0 ;
  0  -1  2  1 ;
  0   0  -1 1 ]

e = eig( m ) ;

n = 30 ;

%// see below for vectorized version
    % for k = [ 1 : n + 1 ]
    %    z1(k) = 2 + 2 * exp(1j * 2 * pi * (k - 1)/ 30) ;
    %    z2(k) = 1 + exp(1j * 2 * pi * (k - 1)/ 30) ;
    % end



%// vectorized loop with 1j as imaginary unit.

z1 = 2 + 2 * exp(1j * 2 * pi * ((1:n+1) - 1)/ 30) ;
z2 = 1 + exp(1j * 2 * pi * ((1:n+1) - 1)/ 30) ;

%// plot the circles and then use scatter for the points. 
plot(real(z1), imag(z1), real(z2), imag(z2));
hold on
scatter(real(e),imag(e))
hold off

which gives the following:

enter image description here

You can of course customize the scatter plot as you wish. Hope that helps!

0
votes

Try this:

h = plot( real(e), imag(e), 'x', real(z1), imag(z1), real(z2), imag(z2) )

More info in the plot documentation.