function svol = SpecVol(T,P,z,w,Tc,Pc,K)
% find specific volume from the Peng-Robinson EOS
global Rgas
Tk = T + 273.15; % K
PkPa = P * 101.325; % kPa
m = 0.37464 + 1.54226 * w - 0.26992 * w .^ 2;
alpha = (1 + m .* (1 - (Tk ./ Tc) .^ 0.5)) .^ 2 ;
a = 0.45724 * Rgas^2 * (Tc .^ 2) ./ Pc .* alpha ;
b = 0.0788 * Rgas * Tc ./ Pc;
Q = ((a * a') .^ 0.5) .* (1 - K) ;
am = z'*Q*z;
bm = z'*b;
V1 = Rgas*Tk/PkPa;
tol = 1e-6;
while (1)
    del = 0.001*V1;
    V2 = V1 + del;
    Vnew = V1 - del * PR(V1,Tk,PkPa,am,bm)/(PR(V2,Tk,PkPa,am,bm)-PR(V1,Tk,PkPa,am,bm));
    if abs((Vnew-V1)/Vnew) < tol ; break ; end
    V1 = Vnew;
end
svol = Vnew;
