Question: can you correct this code on matlab and compleat the code to find pressure saturation and fugacity liquid and fugacity for vapor when philiq equal

can you correct this code on matlab and compleat the code to find pressure saturation and fugacity liquid and fugacity for vapor when philiq equal phivap for each tempretaure.(Tc =658.3; % Critical temperature in K
Pc =1.817e6; % Critical pressure in Pa
omega =0.562; % Acentric factor
% Universal gas constant
R =8.314; % J/(mol K)
b =0.07780* R * Tc / Pc;
kappa =0.37464+1.54226* omega -0.26992* omega^2;
% Reduced temperatures
Tr =[0.7,0.8,0.9,1.0];
%loop
for i=1:length(T)
T=Tr(i);
Tr= T / Tc;
alpha =(1+ kappa *(1- sqrt(T / Tc)))^2;
a =0.45724* R^2* Tc^2/ Pc * alpha;
%initial guess for psat (pa)
if Tr ==0.7
psat=48418;
end
if Tr==0.8
psat=227470;
end
if Tr==0.9
psat=711240;
end
if Tr==1
psat =1704911;
end
tolerance =1e-4;
error=0;
while error < tolerance
%solve
A= a*psat/(R * T)^2;
B = b*psat /(R * T);
coeffs =[1,-1+B, A-(2*B)-(3*B^2),-(A*B)+(B^2)+(B^3)];
z=roots(coeffs);
z=real (z(imag(z)==0)); %keep one real root
z_min = min(z);
z_max = max(z);
%calculate fugacity coefficient
philiq = exp((z_min-1)-log(z_min-B)-(A/(2*sqrt(2)*B))*log((z_min+(1+sqrt(2))*B)/(z_min+(1-sqrt(2))*B)));
phivap = exp((z_max-1)-log(z_max-B)-(A/(2*sqrt(2)*B))*log((z_max+(1+sqrt(2))*B)/(z_max+(1-sqrt(2))*B)));
%calculate psat new
psatnew = psat*(philiq/phivap);
error = abs((philiq/phivap)-1);
psat= psatnew ;
end
end
%calculate volumes
Vliq = z_min*R*T/psat;
Vvap = z_max*R*T/psat;)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Chemical Engineering Questions!