How does one find eigenvalues of a 50 by 50 tridiagonal matrix, with certain conditons?

2 views (last 30 days)
I have a 50 by 50 tridiagonal matrix and this time the entry in first column and first row is -i*gamma and the entry in the last column last row is -i*gamma, every else on this main diagonal is 0 and everything above and below the diagonal is -1. I have to find a condition gamma, where gamma is a real number, that makes the eigenvalues real. I posted a question regarding eigenvalues on March 3rd, and the question was closed. I truly am new to matlab and have been through some brief tutorials. Here is what I have so far:
N=50;
H=zeros(N,N);
x=real(x);
Y=gamma(x);
H(1,1)=-1i*Y;
H(50,50)=-1i*Y;
for i=1:N-1
H(i,i+1)=-1;
H(i+1,i)=-1;
end
disp(H);
When I do this, I receive an error, how can I fix this?

Answers (2)

Brendan Hamm
Brendan Hamm on 5 Mar 2015
Edited: Brendan Hamm on 5 Mar 2015
Is x a scalar or a vector? If it is a vector then you will get a dimension mismatch error as you try and assign a vector to a single element of your matrix.
Furthermore you can avoid the for loop completely using the diag function.
That is:
doc diag
mainDiag = [-1i*Y; zeros(N-2,1); -1i*Y];
offDiag = -ones(N-1,1);
H = diag(mainDiag) + diag(offDiag,-1) + diag(offDiag,1);
Now if you want the eigenvalues:
eigVals = eig(H);
You can also optionally return the associated eigenvectors. Look at the doc for eig:
doc eig
The only other place I could see an error occurring is if you are trying to use your own function gamma() and MATLAB is using the built-in function gamma(). To check:
which gamma -all
The first one listed will be the function you are calling. I would suggest not naming your function the same as a built-in function.

John D'Errico
John D'Errico on 5 Mar 2015
I think you need to start reading the tutorials, MORE. Learn to use MATLAB. The fact that you are using functions to do things that they are not designed to do suggests you need to at least read the help. For example...
x = real(x)
For real x, this does NOT ensure that x will be a real variable from now on. It merely extracts the real part, if x was complex.
Next, you seem to have a variable gamma. Or maybe you just want to define a variable named gamma. Of course, the fact that gamma already exists as avery useful function in MATLAB, is a problem. DON'T DO THAT! It will prevent you from using the gamma function, and soon you will be asking in an anguished voice, why does the gamma function not work for me? Just use a different variable name. gam, perhaps, or gammuh. Pick your favorite alternative spelling.
Next, you are apparently looking for a some value of Y that will force all of the eigenvalues of this matrix to be real. Why do you presume that any such value exists besides the trivial one of zero?
And finally, when you say that something gives you and error, TELL US WHAT IT WAS! Include the complete error. Don't make us read through your code and guess what MATLAB is upset about. Even on this simple code, I can easily create several different errors, if for example, the variable x was already defined by you. Or maybe you have defined variables called "zeros" or "real".

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!