The loop does not take all values
이전 댓글 표시
t=1;
coupj=1;
L = 4;
d = 3;
N_hole=2:2:-2;
tic
%for nume = 1:length(N_hole)
Nh = 2;%N_hole(nume)
N_UP=(L-Nh)/2;
N_DN = (L-Nh)/2;
%***************** Basis generation %************************************
%**************** Hamiltonian parameter ********************************
%pbc=1; % pbc=1 ==> PBC, pbc=0 RBC
%sz=0; %Subblock of sz for the computations
Sz0_space=factorial(L)/(factorial(N_UP)*factorial(N_DN)*factorial(Nh))
%***************************************************************************
%Whole basis computation
basis_spin=zeros(d^L,L);
for i1=1:1:L
ba=0;
for i2=1:1:d^L
basis_spin(i2,i1)=ba;
if mod(i2,d^(L-i1))==0
ba=mod(ba+1,d);
end
end
end
% Chagrge conservation and magnetization conservation
% first we count the number of 1's and 2's in each basis states from
% basis_spin. Then we set condition that if number of 1's = N_UP and number
% of 2's=N_DN then we store those basis from d^L basis states.
szbasis_Ne = zeros(Sz0_space,L);
basis_Ne=zeros(Sz0_space,L);
val=1;
for i2=1:d^L
Loca1 = basis_spin(i2,:)==1;
Loca2 = basis_spin(i2,:)==2;
if (sum(Loca1~=0,2)~=0 && sum(Loca2~=0,2)~=0 && sum(Loca1~=0,2)==N_UP && sum(Loca2~=0,2)==N_DN)
basis_Ne(val,:)=basis_spin(i2,:);
order_sz(1,val)=i2-1;
%order_sz_1(1,val) = bi2de(basis_Ne(val,:), 3,'left-msb');
val=val+1;
end
end
dimension = size(basis_Ne);
dimension = dimension(1);
dn_v1 =cell(L,1);
%***********************************************
for i1 = 1:L
cont1=1;
if i1==L
n=1; m=L;
else
n=i1; m=i1+1;
end
n
m
% Loop over the basis elements
for i2=1:dimension
if basis_Ne(i2,m)==2 && basis_Ne(i2,n)==0
%basis_Ne(i2,:)
%order_sz(i2)
basis_Ne(i2,n)=2;
basis_Ne(i2,m)=0;
%basis_Ne(i2,:)
aux_dn = bi2de(basis_Ne(i2,:), 3,'left-msb');
%aux_dn=order_sz(i2)+(-1)^P*value %Output vector in the whole basis
out_dn=find(order_sz==aux_dn); %Output vector position in the subblock
%We construct the matrix and the complex conjugate
dn_v1{i1}(cont1)=out_dn;
dn_vc1{i1}(cont1)=i2;
dn_w1{i1}(cont1)=i2;
dn_wc1{i1}(cont1)=out_dn;
cont1=cont1+1;
end
end
end
The code does not run for all i2 for i1=L. Could any one help me to figure it out?
댓글 수: 2
Image Analyst
2020년 9월 20일
You need to learn how to debug. Once you do you will be fully enabled for figuring out these simple things on your own.
Just step through and look at what the variable values are and see what lines get executed. Seriously, that's all we would do if we had to do it for you.

Utkarsh Mishra
2020년 9월 20일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

