I wanted to find and plot the eigenvalues of large matrices (around1000x1000). But discovered when using the eig function in matlab, it gives complex eigenvalues when it shouldn't. For example, in the code below I have a Tridiagonal Toeplitz matrix which should have all real eigenvalues. Tridiagonal Toeplitz
But it seems eig is unstable for n=90 and returns a small complex error in a few of the eigenvalues. Is there a way I can get the eigenvalues more accurately?
clear parameters close all clc n=90; dd=-2.*ones(n,1); ud=1.8*ones(n,1); ld=.1*ones(n,1); A = spdiags([ld dd ud],-1:1,n,n); C=full(A); g=eig(C); g=sort(g); cond(C) plot(g,'.')
Any help would be appreciated.