Problem in assigning proper eigevalues in a for-loop
Dear all, I encounter a problem in assigning and plotting the eigenvalues, the final graphs shown 3 separate cosine bands but the locations get some serious problems, causing many discontinuities. I have no idea how to fix it, but I think the problem goes to the fact that matlab does not know how to allocate the eigenvalues correctly for each k in the loop. Here is my code:
theta1= 0.4;
theta2= 0.2;
theta3= 0.4;
theta4= 0.5;
theta5= 0.4;
theta6= 0.3;
theta7= 0.8;
theta8= 0.5;
GellMann1 = [0 1 0; 1 0 0; 0 0 0];
GellMann2 = [0 -1i 0; 1i 0 0; 0 0 0];
GellMann3 = [1 0 0; 0 -1 0; 0 0 0];
GellMann4 = [0 0 1; 0 0 0; 1 0 0];
GellMann5 = [0 0 -1i; 0 0 0; 1i 0 0];
GellMann6 = [0 0 0; 0 0 1; 0 1 0];
GellMann7 = [0 0 0; 0 0 -1i; 0 1i 0];
GellMann8 = [1/sqrt(3) 0 0; 0 1/sqrt(3) 0; 0 0 -2/sqrt(3) ];
normtheta= sqrt(theta1^2 + theta2^2 + theta3^2 + theta4^2 + theta5^2 + theta6^2 + theta6^2 + theta8^2);
PhaseMatrix = theta1*GellMann1 + theta2*GellMann2 + theta3*GellMann3 + theta4*GellMann4 + theta5*GellMann5 + theta6*GellMann6+ theta7*GellMann7 + theta8*GellMann8 ;
J=0.8;
omega_1 = 0.08;
omega_2 = 0.1;
counter_Eigenvalues1_vector =1;
counter_Eigenvalues2_vector =1;
counter_Eigenvalues3_vector =1;
for k = -2*pi : 4*pi/500 : 2*pi
fprintf(‘The corresponding k is %d n’, k);
Hamiltonian= J*(expm(1i*(k*eye(3) – PhaseMatrix)) + expm(-1i*(k*eye(3) – PhaseMatrix)));
eig_Correct = eig(Hamiltonian);
e1correct = eig_Correct(1);
e2correct = eig_Correct(2);
e3correct = eig_Correct(3);
%%%Save the three eigenvalues into an array%%%%
Eigenvalues1_vector(1, counter_Eigenvalues1_vector) = (e1correct);
counter_Eigenvalues1_vector = counter_Eigenvalues1_vector +1;
Eigenvalues2_vector(1, counter_Eigenvalues2_vector) = (e2correct);
counter_Eigenvalues2_vector = counter_Eigenvalues2_vector +1;
Eigenvalues3_vector(1, counter_Eigenvalues3_vector) = (e3correct);
counter_Eigenvalues3_vector = counter_Eigenvalues3_vector +1;
end
%%%Plotting
figure(1)
k = -2*pi : 4*pi/500 : 2*pi
plot(k, Eigenvalues1_vector,k, Eigenvalues2_vector,k,Eigenvalues3_vector)
axis([-2*pi 2*pi -3 3])
xlabel(‘k’)
ylabel(‘E_k’)Dear all, I encounter a problem in assigning and plotting the eigenvalues, the final graphs shown 3 separate cosine bands but the locations get some serious problems, causing many discontinuities. I have no idea how to fix it, but I think the problem goes to the fact that matlab does not know how to allocate the eigenvalues correctly for each k in the loop. Here is my code:
theta1= 0.4;
theta2= 0.2;
theta3= 0.4;
theta4= 0.5;
theta5= 0.4;
theta6= 0.3;
theta7= 0.8;
theta8= 0.5;
GellMann1 = [0 1 0; 1 0 0; 0 0 0];
GellMann2 = [0 -1i 0; 1i 0 0; 0 0 0];
GellMann3 = [1 0 0; 0 -1 0; 0 0 0];
GellMann4 = [0 0 1; 0 0 0; 1 0 0];
GellMann5 = [0 0 -1i; 0 0 0; 1i 0 0];
GellMann6 = [0 0 0; 0 0 1; 0 1 0];
GellMann7 = [0 0 0; 0 0 -1i; 0 1i 0];
GellMann8 = [1/sqrt(3) 0 0; 0 1/sqrt(3) 0; 0 0 -2/sqrt(3) ];
normtheta= sqrt(theta1^2 + theta2^2 + theta3^2 + theta4^2 + theta5^2 + theta6^2 + theta6^2 + theta8^2);
PhaseMatrix = theta1*GellMann1 + theta2*GellMann2 + theta3*GellMann3 + theta4*GellMann4 + theta5*GellMann5 + theta6*GellMann6+ theta7*GellMann7 + theta8*GellMann8 ;
J=0.8;
omega_1 = 0.08;
omega_2 = 0.1;
counter_Eigenvalues1_vector =1;
counter_Eigenvalues2_vector =1;
counter_Eigenvalues3_vector =1;
for k = -2*pi : 4*pi/500 : 2*pi
fprintf(‘The corresponding k is %d n’, k);
Hamiltonian= J*(expm(1i*(k*eye(3) – PhaseMatrix)) + expm(-1i*(k*eye(3) – PhaseMatrix)));
eig_Correct = eig(Hamiltonian);
e1correct = eig_Correct(1);
e2correct = eig_Correct(2);
e3correct = eig_Correct(3);
%%%Save the three eigenvalues into an array%%%%
Eigenvalues1_vector(1, counter_Eigenvalues1_vector) = (e1correct);
counter_Eigenvalues1_vector = counter_Eigenvalues1_vector +1;
Eigenvalues2_vector(1, counter_Eigenvalues2_vector) = (e2correct);
counter_Eigenvalues2_vector = counter_Eigenvalues2_vector +1;
Eigenvalues3_vector(1, counter_Eigenvalues3_vector) = (e3correct);
counter_Eigenvalues3_vector = counter_Eigenvalues3_vector +1;
end
%%%Plotting
figure(1)
k = -2*pi : 4*pi/500 : 2*pi
plot(k, Eigenvalues1_vector,k, Eigenvalues2_vector,k,Eigenvalues3_vector)
axis([-2*pi 2*pi -3 3])
xlabel(‘k’)
ylabel(‘E_k’) Dear all, I encounter a problem in assigning and plotting the eigenvalues, the final graphs shown 3 separate cosine bands but the locations get some serious problems, causing many discontinuities. I have no idea how to fix it, but I think the problem goes to the fact that matlab does not know how to allocate the eigenvalues correctly for each k in the loop. Here is my code:
theta1= 0.4;
theta2= 0.2;
theta3= 0.4;
theta4= 0.5;
theta5= 0.4;
theta6= 0.3;
theta7= 0.8;
theta8= 0.5;
GellMann1 = [0 1 0; 1 0 0; 0 0 0];
GellMann2 = [0 -1i 0; 1i 0 0; 0 0 0];
GellMann3 = [1 0 0; 0 -1 0; 0 0 0];
GellMann4 = [0 0 1; 0 0 0; 1 0 0];
GellMann5 = [0 0 -1i; 0 0 0; 1i 0 0];
GellMann6 = [0 0 0; 0 0 1; 0 1 0];
GellMann7 = [0 0 0; 0 0 -1i; 0 1i 0];
GellMann8 = [1/sqrt(3) 0 0; 0 1/sqrt(3) 0; 0 0 -2/sqrt(3) ];
normtheta= sqrt(theta1^2 + theta2^2 + theta3^2 + theta4^2 + theta5^2 + theta6^2 + theta6^2 + theta8^2);
PhaseMatrix = theta1*GellMann1 + theta2*GellMann2 + theta3*GellMann3 + theta4*GellMann4 + theta5*GellMann5 + theta6*GellMann6+ theta7*GellMann7 + theta8*GellMann8 ;
J=0.8;
omega_1 = 0.08;
omega_2 = 0.1;
counter_Eigenvalues1_vector =1;
counter_Eigenvalues2_vector =1;
counter_Eigenvalues3_vector =1;
for k = -2*pi : 4*pi/500 : 2*pi
fprintf(‘The corresponding k is %d n’, k);
Hamiltonian= J*(expm(1i*(k*eye(3) – PhaseMatrix)) + expm(-1i*(k*eye(3) – PhaseMatrix)));
eig_Correct = eig(Hamiltonian);
e1correct = eig_Correct(1);
e2correct = eig_Correct(2);
e3correct = eig_Correct(3);
%%%Save the three eigenvalues into an array%%%%
Eigenvalues1_vector(1, counter_Eigenvalues1_vector) = (e1correct);
counter_Eigenvalues1_vector = counter_Eigenvalues1_vector +1;
Eigenvalues2_vector(1, counter_Eigenvalues2_vector) = (e2correct);
counter_Eigenvalues2_vector = counter_Eigenvalues2_vector +1;
Eigenvalues3_vector(1, counter_Eigenvalues3_vector) = (e3correct);
counter_Eigenvalues3_vector = counter_Eigenvalues3_vector +1;
end
%%%Plotting
figure(1)
k = -2*pi : 4*pi/500 : 2*pi
plot(k, Eigenvalues1_vector,k, Eigenvalues2_vector,k,Eigenvalues3_vector)
axis([-2*pi 2*pi -3 3])
xlabel(‘k’)
ylabel(‘E_k’) eigenvalues, sorting, plotting MATLAB Answers — New Questions