I am messing up Eigenvalues in a loop...Help me please.
Afficher commentaires plus anciens
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).

Réponse acceptée
Plus de réponses (1)
John D'Errico
le 28 Août 2016
2 votes
1 commentaire
Philipp Marx
le 28 Août 2016
Modifié(e) : Philipp Marx
le 28 Août 2016
Catégories
En savoir plus sur Linear Algebra dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!