%% Types of Eigenvalues
% west0479 is a real-valued 479-by-479 sparse matrix with both real and complex pairs of conjugate eigenvalues.
% Load the west0479 matrix, then compute and plot all of the eigenvalues using eig. Since the eigenvalues are complex, plot automatically uses the real parts as the x-coordinates and the imaginary parts as the y-coordinates.

load west0479
A = west0479;
d = eig(full(A));
plot(d,'+')

% The eigenvalues are clustered along the real line (x-axis), particularly near the origin.
%
% eigs has several options for sigma that can pick out the largest or smallest eigenvalues of varying types. Compute and plot some eigenvalues for each of the available options for sigma.

figure
plot(d, '+')
hold on
la = eigs(A,6,'largestabs');
plot(la,'ro')
sa = eigs(A,6,'smallestabs');
plot(sa,'go')
hold off
legend('All eigenvalues','Largest magnitude','Smallest magnitude')
xlabel('Real axis')
ylabel('Imaginary axis')

%
%

figure
plot(d, '+')
hold on
ber = eigs(A,4,'bothendsreal');
plot(ber,'r^')
bei = eigs(A,4,'bothendsimag');
plot(bei,'g^')
hold off
legend('All eigenvalues','Both ends real','Both ends imaginary')
xlabel('Real axis')
ylabel('Imaginary axis')

%

figure
plot(d, '+')
hold on
lr = eigs(A,3,'largestreal');
plot(lr,'ro')
sr = eigs(A,3,'smallestreal');
plot(sr,'go')
li = eigs(A,3,'largestimag','SubspaceDimension',45);
plot(li,'m^')
si = eigs(A,3,'smallestimag','SubspaceDimension',45);
plot(si,'c^')
hold off
legend('All eigenvalues','Largest real','Smallest real','Largest imaginary','Smallest imaginary')
xlabel('Real axis')
ylabel('Imaginary axis')

% Copyright 2012 The MathWorks, Inc.