I am messing up Eigenvalues in a loop...Help me please.

clear
g=0.1; E0=9.8; A=1; B=0;
E = 5:0.01:15;
for i=1:length(E);
H=[E(i),g/sqrt(2),g/sqrt(2);g/sqrt(2),E0,A;g/sqrt(2),B,E0];
[EIGVEC,EIGVAL]=eig(H);
EIGVAL1(i)=EIGVAL(1); EIGVAL2(i)=EIGVAL(5); EIGVAL3(i)=EIGVAL(9);
end
figure
plot(E,real(EIGVAL1),'g',E,real(EIGVAL2),'r',E,real(EIGVAL3),'b')
Matlab is calculating the eigenvalues for every i. The calculated valus are allright the problem is that i am not able to give them any order. If you watch the plot you can see that Matlab is switching between eigenvalue number 1,2,3.
If you want to see the final plot without mistakes i have made it allready with other methods, but i need the working code for following physics problems (and for learning how to Matlab of course).

 채택된 답변

Philipp Marx
Philipp Marx 2016년 8월 30일

0 개 추천

Just replacing eig() with eigs() solves the problem.

댓글 수: 1

John D'Errico
John D'Errico 2016년 8월 30일
편집: John D'Errico 2016년 8월 30일
NO. IT DOES NOT SOLVE THE PROBLEM. Eigs is not designed to solve that problem. You got lucky, and the different order that eigs might return happens to work for you.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John D'Errico
John D'Errico 2016년 8월 28일

2 개 추천

Download eigenshuffle . It is designed to solve exactly this problem.

댓글 수: 1

Philipp Marx
Philipp Marx 2016년 8월 28일
편집: Philipp Marx 2016년 8월 28일
How can i make this working with my code? I am a totally Matlab beginner. I dont get it running.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Eigenvalues & Eigenvectors에 대해 자세히 알아보기

질문:

2016년 8월 28일

편집:

2016년 8월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by