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?
matrix = diag(0:20);
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)