我是在问问题,这个是我写的程序,其实跟最小二乘法有关:
function [a1,b1,a2,b2]=forcefieldfitting(r,e)
%使用DFT计算的数据拟合力场参数,e是使用量化计算出现的相互作用能,r是两个分子片段之间的距离
%LJ-12-06公式中的EPSILON(C):a1
%LJ-12-06公式中的SIGMA(C):b1
%LJ-12-06公式中的EPSILON(O):a2
%LJ-12-06公式中的SIGMA(O):b2
%单个的CO2的能量可以认为是两个O的能量和一个C的能量的加和
if(length(e)==length(r))
n=length(e);
else
disp('e和r的维数不相等!');
return;
end %维数检查
A=zeros(4,3)
B=zeros(4,2);
for i=1:n
A(1,1)=A(1,1)+(384*a1^2*b1^23)/r(i)^24;
A(1,2)=A(1,2)+(192*a1^2*b1^11)/r(i)^12;
A(1,3)=A(1,3)+(48*a1*e*b1^5)/r(i)^6;
A(2,1)=A(2,1)+(32*a1*b1^24)/r(i)^24;
A(2,2)=A(2,2)+(32*a1*b1^12)/r(i)^12
A(2,3)=A(2,3)+(8*e(i)*b1^6)/r(i)^6;
A(3,1)=A(3,1)+(1536*a2^2*b2^23)/r(i)^24;
A(3,2)=A(3,2)+(768*a2^2*b2^23)/r(i)^12;
A(3,3)=A(3,3)+(96*a2*e(i)*b2^5)/r(i)^6;
A(4,1)=A(4,1)+(128*a2*b2^24)/r(i)^24;
A(4,2)=A(4,2)+(128*a2*b2^12)/r(i)^12;
A(4,3)=A(4,3)+(16*e(i)*b2^6)/r(i)^6;
B(1,1)=B(1,1)+(576*a1^2*b1^17)/r(i)^18;
B(1,2)=B(1,2)+(96*a1*e(i)*b1^11)/r(i)^12;
B(2,1)=B(2,1)+(64*a1*b1^18)/r(i)^18;
B(2,2)=B(2,2)+(8*e(i)*a1^12)/r(i)^12;
B(3,1)=B(3,1)+(2304*a2^2*b2^17)/r(i)^18;
B(3,2)=B(3,2)+(192*a2*e(i)*b2^11)/r(i)^12;
B(4,1)=B(4,1)+(256*a2*b2^18)/r(i)^18;
B(4,3)=B(4,3)+(16*e(i)*b2^12)/r(i)^12;
end
s=A\B;
a1=s(1);
b1=s(2);
a2=s(3);
b2=s(4);