Gcalc

%% Information 

%%GCALC(GA,GB,xB,T,I0AB,I1AB,I2AB,I3AB,I4AB,I5AB) is for calculating Gibbs energy 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[G]= GCALC(varargin)

narginchk(5,10)

R=8.314;

if nargin==5

    GA=varargin{1};

    GB=varargin{2};

    xB=varargin{3};

    xA=1-xB;

    T=varargin{4};

    IAB=varargin{5};

switch xB

    case {0,1}

        G=GA*xA+GB*xB;

    otherwise

        G=GA*xA+GB*xB+R*T*(xA*log(xA)+xB*log(xB))+xA*xB*IAB;

end

end


if nargin==6

    GA=varargin{1};

    GB=varargin{2};

    xB=varargin{3};

    xA=1-xB;

    T=varargin{4};

    IAB=varargin{5}+varargin{6}*(1-2*xB);%???????

switch xB

    case {0,1}

        G=GA*xA+GB*xB;

    otherwise

        G=GA*xA+GB*xB+R*T*(xA*log(xA)+xB*log(xB))+xA*xB*IAB;

end

end


if nargin==7

    GA=varargin{1};

    GB=varargin{2};

    xB=varargin{3};

    xA=1-xB;

    T=varargin{4};

    IAB=varargin{5}+varargin{6}*(1-2*xB)+varargin{7}*(1-2*xB)^2;%???????

switch xB

    case {0,1}

        G=GA*xA+GB*xB;

    otherwise

        G=GA*xA+GB*xB+R*T*(xA*log(xA)+xB*log(xB))+xA*xB*IAB;

end

end


if nargin==8

    GA=varargin{1};

    GB=varargin{2};

    xB=varargin{3};

    xA=1-xB;

    T=varargin{4};

    IAB=varargin{5}+varargin{6}*(1-2*xB)+varargin{7}*(1-2*xB)^2+varargin{8}*(1-2*xB)^3;%???????

switch xB

    case {0,1}

        G=GA*xA+GB*xB;

    otherwise

        G=GA*xA+GB*xB+R*T*(xA*log(xA)+xB*log(xB))+xA*xB*IAB;

end

end


if nargin==9

    GA=varargin{1};

    GB=varargin{2};

    xB=varargin{3};

    xA=1-xB;

    T=varargin{4};

    IAB=varargin{5}+varargin{6}*(1-2*xB)+varargin{7}*(1-2*xB)^2+varargin{8}*(1-2*xB)^3+varargin{9}*(1-2*xB)^4;%???????

switch xB

    case {0,1}

        G=GA*xA+GB*xB;

    otherwise

        G=GA*xA+GB*xB+R*T*(xA*log(xA)+xB*log(xB))+xA*xB*IAB;

end

end


if nargin==10

    GA=varargin{1};

    GB=varargin{2};

    xB=varargin{3};

    xA=1-xB;

    T=varargin{4};

    IAB=varargin{5}+varargin{6}*(1-2*xB)+varargin{7}*(1-2*xB)^2+varargin{8}*(1-2*xB)^3+varargin{9}*(1-2*xB)^4+varargin{10}*(1-2*xB)^5;%???????

switch xB

    case {0,1}

        G=GA*xA+GB*xB;

    otherwise

        G=GA*xA+GB*xB+R*T*(xA*log(xA)+xB*log(xB))+xA*xB*IAB;

end

end

end