ddG
ddGCALC(xB,T,I0AB,I1AB,I2AB,I3AB,I4AB,I5AB) is for calculating the second derivative Gibbs of binary single solution system.
%% Information
%ddGCALC(xB,T,I0AB,I1AB,I2AB,I3AB,I4AB,I5AB) is for calculating the second derivative Gibbs of binary single solution system..
% I0AB,I1AB,I2AB,I3AB,I4AB,I5AB are parameters of Redlich-Kister binary excess model (Redlich & Kister, 1948)
%Contact: x.chen@mpie.de
function[ddG]= ddGCALC(varargin)
narginchk(3,8)
R=8.314;
if nargin==3
xB=varargin{1};
xA=1-xB;
T=varargin{2};
IAB=varargin{3};
switch xB
case {0,1}
ddG=R*T*(1/xB+1/(xA))-2*IAB; %+0.00001 for preventing Inf cases
otherwise
ddG=R*T*(1/xB+1/(xA))-2*IAB;
end
end
if nargin==4
xB=varargin{1};
xA=1-xB;
T=varargin{2};
IAB=varargin{3}+varargin{4}*(1-2*xB);%???????
dIAB=varargin{4}*(-2);
switch xB
case {0,1}
ddG=R*T*(1/(xB+0.00001)+1/(xA+0.00001))-2*IAB+(1-2*xB)*dIAB+(1-2*xB)*dIAB;
otherwise
ddG=R*T*(1/xB+1/(xA))-2*IAB+(1-2*xB)*dIAB+(1-2*xB)*dIAB;
end
end
if nargin==5
xB=varargin{1};
xA=1-xB;
T=varargin{2};
IAB=varargin{3}+varargin{4}*(1-2*xB)+varargin{5}*(1-2*xB)^2;%???????
dIAB=varargin{4}*(-2)+varargin{5}*(8*xB-4);%???????
ddIAB=varargin{5}*8;
switch xB
case {0,1}
ddG=R*T*(1/(xB+0.00001)+1/(xA+0.00001))-2*IAB+(1-2*xB)*dIAB+(1-2*xB)*dIAB+ xA*xB*ddIAB;
otherwise
ddG=R*T*(1/xB+1/(xA))-2*IAB+(1-2*xB)*dIAB+(1-2*xB)*dIAB+ xA*xB*ddIAB;
end
end
if nargin==6
xB=varargin{1};
xA=1-xB;
T=varargin{2};
IAB=varargin{3}+varargin{4}*(1-2*xB)+varargin{5}*(1-2*xB)^2+varargin{6}*(1-2*xB)^3;%???????
dIAB=varargin{4}*(-2)+varargin{5}*(8*xB-4)+varargin{6}*(-6*(2*xB-1)^2);%???????
ddIAB=varargin{5}*8+varargin{6}*(24 - 48*xB);
switch xB
case {0,1}
ddG=R*T*(1/(xB+0.00001)+1/(xA+0.00001))-2*IAB+(1-2*xB)*dIAB+(1-2*xB)*dIAB+ xA*xB*ddIAB;
otherwise
ddG=R*T*(1/xB+1/(xA))-2*IAB+(1-2*xB)*dIAB+(1-2*xB)*dIAB+ xA*xB*ddIAB;
end
end
if nargin==7
xB=varargin{1};
xA=1-xB;
T=varargin{2};
IAB=varargin{3}+varargin{4}*(1-2*xB)+varargin{5}*(1-2*xB)^2+varargin{6}*(1-2*xB)^3+varargin{7}*(1-2*xB)^4;%???????
dIAB=varargin{4}*(-2)+varargin{5}*(8*xB-4)+varargin{6}*(-6*(2*xB-1)^2)+varargin{7}*(8*(2*xB-1)^3);%???????
ddIAB=varargin{5}*8+varargin{6}*(24 - 48*xB)+varargin{7}*(48*(2*xB-1)^2);
switch xB
case {0,1}
ddG=R*T*(1/(xB+0.00001)+1/(xA+0.00001))-2*IAB+(1-2*xB)*dIAB+(1-2*xB)*dIAB+ xA*xB*ddIAB;
otherwise
ddG=R*T*(1/xB+1/(xA))-2*IAB+(1-2*xB)*dIAB+(1-2*xB)*dIAB+ xA*xB*ddIAB;
end
end
if nargin==8
xB=varargin{1};
xA=1-xB;
T=varargin{2};
IAB=varargin{3}+varargin{4}*(1-2*xB)+varargin{5}*(1-2*xB)^2+varargin{6}*(1-2*xB)^3+varargin{7}*(1-2*xB)^4+varargin{8}*(1-2*xB)^5;%???????
dIAB=varargin{4}*(-2)+varargin{5}*(8*xB-4)+varargin{6}*(-6*(2*xB-1)^2)+varargin{7}*(8*(2*xB-1)^3)+varargin{8}*(-10*(2*xB - 1)^4);%???????
ddIAB=varargin{5}*8+varargin{6}*(24 - 48*xB)+varargin{7}*(48*(2*xB-1)^2)+varargin{8}*(-80*(2*xB-1)^3);
switch xB
case {0,1}
ddG=R*T*(1/(xB+0.00001)+1/(xA+0.00001))-2*IAB+(1-2*xB)*dIAB+(1-2*xB)*dIAB+ xA*xB*ddIAB;
otherwise
ddG=R*T*(1/xB+1/(xA))-2*IAB+(1-2*xB)*dIAB+(1-2*xB)*dIAB+ xA*xB*ddIAB;
end
end
end