Академический Документы
Профессиональный Документы
Культура Документы
end
end
end
end
% Self-consistent loop
C=ones(1,asize(2)); %initial guess
nor=C*S*C'
disp('Initial Guess');
C=C/nor
Elast=1;
EVal=0;
P=C'*C;
count=0;
rplot=-2:0.01:3; % range in atomic units (bohr) for plotting
the probability density
% figure();
% Generating Fock matrix
while((abs(EVal(1)-Elast))>0.000001)
count=count+1;
disp('Step #');
disp(count);
Elast=EVal(1)
for i=1:8
for j=1:8
J=0;
for k=1:8
for l=1:8
J=J+P(k,l)*g(i,j,k,l);
end
end
F(i,j)=T(i,j)+A(i,j)+J;
end
end
% solve the generalized eigenvalue problem FC=ESC
% inverse of V is its conjugate transpose because V is unitary
Fp=V'*F*V; % modified Fock matrix
[Vecp,Val]=eig(Fp);
Vec=V*Vecp;
EigVal=diag(Val,0)
[EVal,index]=sort(EigVal);
disp('Ground State eigenvalue from this step is (in a.u.,
i.e. Hartree):');
Erec(count)=EVal(1) % lowest eigenvalue
GrCoeff=Vec(:,index(1)); % eigenvector corresponding to
ground state
disp('C matrix from this step is:');
C=GrCoeff.' %new C matrix, this is normalized w.r.t. S ie.
C*S*C'=1
disp('Input density matrix for next step is:');
P=0.8*P+0.2*C'*C %new input density matrix
GndWvFn=C(1:4)*exp(-(alpha(1:4)).'*(rplot.*rplot))
+C(5:8)*exp(-(alpha(5:8)).'*((rplot-r).*(rplot-r))); % ground
state wavefunction from STO-4G approximation
%
Uncomment the next 4 lines if you need a plot of probability
with step of convergence
%
hold on;
%
plot(rplot,(abs(GndWvFn)).^2,'r--','LineWidth',1.5);
%
xlabel('r position');
%
ylabel('Probability density');
%
title('Plot of the probability density vs. r position with
step of convergence');
end
Qs=0;
for i=1:8
for j=1:8
for k=1:8
for l=1:8
Qs=Qs+g(i,j,k,l)*C(i)*C(j)*C(k)*C(l);
end
end
end
end
disp('The final total energy (including nuclear-nuclear
repulsion) after convergence for this H-H bond is ');
Eg(y)=2*C*(T+A)*C'+Qs+NNr; % the energy from h for each e, the
e-e interaction and the nucleus-nucleus interaction added
disp(Eg(y));
if Eg(y)==min(Eg)
rmin = r;
Erecmin = Erec;
WvFnmin = GndWvFn;
end
end
figure();
plot([0.5:0.05:2.5],Eg,'bo','LineWidth',2);
title('Plot showing total energy from Hartree Fock treatment of HH using Born Oppenheimer approximation');
xlabel('H-H bondlength');
ylabel('Total energy (in a.u.)');
grid on;
disp('The least energy bond length (A) for H-H is ');
disp(rmin*0.529177);
disp('The energy (Hartree) of this bond is '); disp(min(Eg));
figure();
plot(Erecmin,'ro','LineWidth',2);
axis([1 count min(Erecmin) max(Erecmin)+0.1]);
title('Plot showing convergence of Fock level with every step for
the least energy H-H bondlength');
xlabel('Step of convergence');
ylabel('Fock energy level (in a.u.)');
grid on;
%plot of final probabiliy density
figure();
plot(rplot,(abs(WvFnmin)).^2,'LineWidth',2.5);
xlabel('r position');
ylabel('Probability density');
title('Plot of the probability density of electrons vs. r position
for the least energy H-H bond');
axis tight;
grid on;
%print result