function f=Kval_PR(xx)
%Main Program that assembles all equations.
%K-value calculation from Peng-Robinson equation
%Components - propane, isopentane.

Tc  =[369.83 460.40]; %K
Pc  =[44.46  33.8]; %bar
w   =[0.15229 0.227875];
k(2,2) = 0;
k(1,2) = 2.58e-003; %propane-isopentane binary interaction for PR EOS
k(2,1)=k(1,2);
T = 348.15; % K (167 F)
P =10.135;  %bar (147 psia) 

%Transfer the guesses to composition vectors
x([1 2]) = [xx(1) xx(2)];
y=xx([3:4]);

%Compute fugacity of each species in both phases
for i=1:2
 fl(i) = fugL(T,P,Tc,Pc,w,k,x,i);
 fv(i) = fugV(T,P,Tc,Pc,w,k,y,i);
 f(i) = fl(i) - fv(i);
end

%Summation constraint

f(3) = sum(x) - 1;
f(4) = sum(y) - 1;

