% Calc.m : The function Calc takes the values given to it, applies them to
% the required equation and returns what the 'z' value is at this point
% with these values.
%
% Changed by k.bryan to allow arrays of Temp and time vectors
% Changed by k.bryan to allow arrays of value vectors
% Changed by c.monk (9/10/09) to agree with Sigmaplot equation 
function value = calc(Temp,Time,DeltaGCat,DeltaGInact,DeltaHEq,TEq,E0,h,Kb,R)

[m1,n1]=size(Temp);
[m2,n2]=size(DeltaGCat);

%make arrays out of the values
if n1==m2
    DeltaGCat=ones(m1,1)*DeltaGCat';
    DeltaGInact=ones(m1,1)*DeltaGInact';
    DeltaHEq=ones(m1,1)*DeltaHEq';
    TEq=ones(m1,1)*TEq';
elseif m2>1
    DeltaGCat=ones(m1,1)*DeltaGCat';
    DeltaGInact=ones(m1,1)*DeltaGInact';
    DeltaHEq=ones(m1,1)*DeltaHEq';
    TEq=ones(m1,1)*TEq';
    Time=Time*ones(1,m2);
    Temp=Temp*ones(1,m2);
end

%[m1,n1]=size(Temp)
%[m2,n2]=size(DeltaGCat)

    
% This is some calculation of values that are repeated in the main equation
A = exp(-(DeltaGCat)./(R.*Temp));
B = exp(-(DeltaGInact)./(R.*Temp));
C = exp(-(DeltaHEq.*(1./Temp-1./TEq))./R);
D = h.*(1+C);

% Main equation to calculate the value at the given point.
% value = ((A.*E0)./(B.*C)).*(1-exp(-(Kb.*Temp.*B.*C.*Time)./D));
 value = -((Kb.*Temp./h).*A.*E0./(((Kb.*Temp./h).*B.*C))).*exp(-((Kb.*Temp./h).*B.*C./(1+C)).*Time)+(Kb.*Temp./h).*A.*E0./((Kb.*Temp./h).*B.*C

end


%
% A=Kb.*Temp./h.*exp(DeltaGInact/(R.*Temp)).*E0
% B=(1+exp((-DeltaHEq./R).*(1/Temp-1/TEq)));
% value=A./B;
%
%
%
%