-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkEigenvalues.m
63 lines (45 loc) · 2.04 KB
/
checkEigenvalues.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function [] = checkEigenvalues(SparseMatA, filename, testCaseName)
[m n] = size(SparseMatA);
% The first measure of conditioning:
fprintf(1,'Condition Number (condest(A) [for 1-norm estimate]): %e\n', condest(SparseMatA));
% Force OCTAVE to flush output. Matlab calls this by default
flush_io(1);
% Compute all Eigenvalues (LAMBDA) and Vectors (V)
[V, LAMBDA] = eig(full(SparseMatA));
figure;
hold off; % clear plot if anything is already there
eigenvalues = diag(LAMBDA);
plot(eigenvalues, 'ko');
axis('square');
if (nargin < 3)
titlestr=sprintf('Complex Plane Eigenvalue Plot for %s (Num Eigenvalues = %d)', filename, m);
title(titlestr);
else
titlestr1=sprintf('[%s] ', testCaseName);
titlestr2=sprintf('Complex Plane Eigenvalue Plot for %s (Num Eigenvalues = %d)', filename, m);
title({titlestr1,titlestr2});
end
xlabel('Real');
ylabel('Imaginary');
%print('fullMatEigenvalues.png', '-dpng', '-r300');
save('EigenVectors_realpart.mtx', 'V', '-ascii');
save('EigenVectors.mat', 'V', '-mat');
%[err] = mmwrite('Eigenvectors.mtx',V, 'Indicates non-symmetric edges. Row=StencilID, Col=Stencils which do not contain StencilID');
save('EigenValues_realpart.mtx', 'eigenvalues', '-ascii');
save('EigenValues.mat', 'eigenvalues', '-mat');
% Q: how many eigenvalues are 0 or larger
numGreater = length(find(real(eigenvalues) >= 0));
fprintf(1,'Number of EigenValues >= 0: %d\n', numGreater);
% Q: how many eigenvalues are very close to 0 or larger?
numGreater = length(find(real(eigenvalues) >= -1e-6));
fprintf(1,'Number of EigenValues >= -1e-6: %d\n', numGreater);
% Q: how many eigenvalues are greater than -1?
numGreater = length(find(real(eigenvalues) > -1));
fprintf(1,'Number of EigenValues > -1: %d\n', numGreater);
% Q: whats the MAX eigenvalue?
[mx ind] = max(real(eigenvalues));
fprintf(1, 'Max EigenValue: %g+%gi\n', real(eigenvalues(ind)), imag(eigenvalues(ind)));
% Q: whats the MIN eigenvalue?
[mn ind] = min(real(eigenvalues));
fprintf(1, 'Min EigenValue: %g+%gi\n', real(eigenvalues(ind)), imag(eigenvalues(ind)));
end