eigs bug for 0 as lowest eigenvalue in parts of the matlab versions
Mostra commenti meno recenti
I'm eigs a sparse diagonal matrix that has 0 as the lowest eigenvalue but in some new versions of matlab it gets 1 as the wrong answer.
This is a code that get wrong results in matlab 2017b and 2018b2017b and 2018b, while gets the right answer in matlab 2016a and the online matlab. I'm comparing eig and eigs for identical matrix. The right answer will be always 0 0, and the wrong answer will always be 1 and 0. Sparse eigs has missed 0 as my lowest eigenvalue.
So is there any way to gurantee it right?
%%% my code
clearvars
clc
matrix = diag(0:20);
% matrix(1,1)=1;
% matrix(2,2)=0;
sp_matrix = sparse(matrix);
Eg_sp = eigs(sp_matrix,1,'sa');
Es = eig(matrix);
Es = sort(Es);
Eg_full = Es(1);
fprintf('Eg by sparse matrix is %f\n',Eg_sp)
fprintf('Eg by full matrix is %f\n',Eg_full)
1 Commento
Walter Roberson
il 18 Mag 2019
R2019a for Mac gives -9.04753446879501e-17 for the Eg_sp, but R2018b for Mac gives 1 - 1.4432899320127e-15
Risposta accettata
Più risposte (2)
Matt J
il 18 Mag 2019
That does seem like an interesting bug. This seems to work though
Eg_sp = eigs(sp_matrix,1,1e-12);
1 Commento
pages larry
il 18 Mag 2019
David Goodmanson
il 18 Mag 2019
Modificato: David Goodmanson
il 18 Mag 2019
Hi pl,
2018b does not list 'sa' as an option for eigs, so I am speculating that that 'sa' is legacy. However, compariing 'sa' to 'smallestabs',
matrix = diag(0:20);
sp_matrix = sparse(matrix);
Eg_sp = eigs(sp_matrix,1,'sa')
Eg_sp = 1.0000 % incorrect
Eg_sp = eigs(sp_matrix,1,'smallestabs') % this errors out,
% error message suggests that the smallest eigenvalue is 0
% checking for small nonzero smallest eigenvalue
sp_matrix(1,1)=1e-10;
Eg_sp = eigs(sp_matrix,1,'smallestabs')
Eg_sp = 1.0000e-10
sp_matrix(1,1)=1e-100;
Eg_sp = eigs(sp_matrix,1,'smallestabs')
Eg_sp = 1.0000e-100 % but with a warning that the matrix is almost singular
so it appears that you could trap for zero eigenvalue, and then the other cases are covered.
Categorie
Scopri di più su Sparse Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!