0% found this document useful (0 votes)
110 views7 pages

Matlab Programming Strategy For Vle With Eos

This MATLAB code is simulating a vapor-liquid equilibrium (VLE) calculation for a binary mixture using an equation of state (EOS). It uses an iterative approach with inner and outer loops. The inner loop calculates the fugacity coefficients and mole fractions repeatedly until the mole fraction sum converges. The outer loop adjusts the temperature until the mole fraction sum is 1, indicating vapor-liquid equilibrium is reached. The code implements typical steps for this type of calculation including initializing conditions, evaluating thermodynamic properties, implementing mixing rules, solving the EOS, and iteratively converging on the VLE solution.

Uploaded by

matheus735
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views7 pages

Matlab Programming Strategy For Vle With Eos

This MATLAB code is simulating a vapor-liquid equilibrium (VLE) calculation for a binary mixture using an equation of state (EOS). It uses an iterative approach with inner and outer loops. The inner loop calculates the fugacity coefficients and mole fractions repeatedly until the mole fraction sum converges. The outer loop adjusts the temperature until the mole fraction sum is 1, indicating vapor-liquid equilibrium is reached. The code implements typical steps for this type of calculation including initializing conditions, evaluating thermodynamic properties, implementing mixing rules, solving the EOS, and iteratively converging on the VLE solution.

Uploaded by

matheus735
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

MATLAB PROGRAMMING STRATEGY FOR VLE WITH EOS

Refer to Second Assignment


yi=[.......; ........]; % feed composition in mole fraction P =......; % Define system pressure in Pa R =........; % in m3 Pa mol-1 K-1 An=[.....;......]; Bn=[....; .....]; Cn=[....,.....]; % Antoine Equation Constant Guess Temperature (T); Calc. Psat from Antoine Equation Calc. Ki from Shortcut Method/Raoult (Ki=Pisat/P) Calc. xi (xi=Ki/yi) ==> untuk menghitung iL , V untuk first iteration i Awal Outer Loop dengan kondisi set temporary variable: dif1=0; sum_xi_old=sum(xi); while (dif1 > 1E-5); % Outer Loop Calc. mixing rule: B, B , Z, A , etc. needed by fugacity calculation k ij

iL , V i Calc.

(no need at second loop and so on) set temporary var: dif2=1; while (dif2 > 1E-5) Calc. Ki (Ki= L/ v) i i

... (cont....2)

Calc. xi=yi/Ki Calc. sum_xi Calc. dif2 = abs (sum_xi_old sum_xi) set: sum_xi_old=sum_xi normalize: xi=xi/sum_xi Calc. mixing rule: B, Bk, Z, Aij, etc. needed by fugacity calculation with new xi Calc. iL with new xi

end; %(inner loop) calc. condition: dif1=abs(1-sum_xi); % T guess adjustment if (sum_xi > 1); T=T+0.1; % 0.1 can be adjusted elseif (sum_xi < 1); T=T-0.1; % 0.1 can be adjusted end end ; %(outer loop)

clc clear % feed composition: yio=[0.5;0.5]; %C5H12 and C4H10 initial composition P=14 bar; %total presure = 14 bar P=P*1E5; % P in Pa % define critical Properties of pentane and butane Tc=[469.7; 425.2]; %pentane and butane (K) Pc=[3.369; 3.797]; % (MPa) Pc=Pc/1000; % Pc in Pa w= ; % omega critical R=8.314; % R in m3.Pa/mol.K An=[ ; ]; % Antoine Constant Bn=[ ; ]; % Antoine Constant Cn=[ ; ]; % Antoine Constant T= ; % Guess Temperature Psat=10.^(A-(B./(T+C))); % Calculate P saturated using Antoine Kio=Psat/P; % Calculate Ki from Raoult Law for first iteration xio=Kio./yio; % Calculate xi for computing phiL & phiV at first iteration

% set temporary vaiables dif1=0; sum_xi_old=sum(xio); yi=yio; xi=xio; kij=0; % binary interaction parameters while (dif1 > 1E-5); % Outer Loop % Calculate mixing rule Kappa=0.37464 + 1.54226*w -0.26993*w.^2; % Kappa [C5H12 dan C4H10] Alfa=(1+Kappa.*(1-sqrt(T./Tc))).^2; % Alfa [C5H12 dan C4H10] b=0.07779607*R*Tc./Pc; % b pure component [C5H12 dan C4H10] ac=0.45723553*((R^2.*Tc.^2)./Pc); % ac [C5H12 dan C4H10] a=ax.*Alfa; % a pure component [C5H12 dan C4H10] Bi=b*P/(R*T); % Bi for component i in solution Ai=a*P/(R^2*T^2); % Ai for component i in solution % Calculate A & B for from mixing rule Bt=0; At=0; for i=1:length(yio) B(i)=yi(i)*Bi(i); Ajt=0; for j=1:length(yio) Aij(j)=sqrt(Ai(i)*Ai(j))*(1-kij); Ajt=Ajt+Aij(j); end At=At+Ajt; Bt=Bt+B(i); end B=Bt; % B from mixing rule A=At; % A from mixing rule

% Calculate Compressibility Factor from EOS (Z) Z= % Calculate Fugacity coefficient (phiL) for k=1:length(yio) phi1=-(log(Z-B)); phi2=Bi(k)*(Z-1)/B; phi3=(A/(B*sqrt(8)))*log((Z+(1+sqrt(2))*B)/(Z+(1-sqrt(2))*B); sphi4t=0; for j=1:length(yio) Ajk=sqrt(Ai(j)*Ai(k))*(1-kij); sphi4t=sphi4t + xi(j)*Ajk; end phi4=phi3*((2*sphi4t/A) - (B(k)/B)); phiL(k)=phi1+phi2-phi4; end % Calculate Fugacity coefficient (phiV) for k=1:length(yio) phi1=-(log(Z-B)); phi2=Bi(k)*(Z-1)/B; phi3=(A/(B*sqrt(8)))*log((Z+(1+sqrt(2))*B)/(Z+(1-sqrt(2))*B); sphi4t=0; for j=1:length(yio) Ajk=sqrt(Ai(j)*Ai(k))*(1-kij); sphi4t=sphi4t + yi(j)*Ajk; end phi4=phi3*((2*sphi4t/A) - (B(k)/B)); phiV(k)=phi1+phi2-phi4; end

%set temporary variable for inner loop dif2=0; while (dif2 > 1E-5); % inner loop Ki=phiL./phiV; % Ki [C5H12; C4H10] xi=yi./Ki; sum_xi=sum(xi); dif2=abs(sum_xi_old - sum_xi); sum_xi_old=sum_xi; xi=xi./sum_xi; % normalize xi for next iteration % Calculate Fugacity coefficient (phiL) at new xi for k=1:length(yio) phi1=-(log(Z-B)); phi2=Bi(k)*(Z-1)/B; phi3=(A/(B*sqrt(8)))*log((Z+(1+sqrt(2))*B)/(Z+(1-sqrt(2))*B); sphi4t=0; for j=1:length(yio) Ajk=sqrt(Ai(j)*Ai(k))*(1-kij); sphi4t=sphi4t + xi(j)*Ajk; end phi4=phi3*((2*sphi4t/A) - (B(k)/B)); phiL(k)=phi1+phi2-phi4; end end; % end of inner loop dif1=abs(1-sum_xi; % T guess adjustment if (sum_xi > 1); T=T+0.1; % 0.1 can be set elseif (sum_xi < 1); T=T-0.1; % 0.1 can be set end end; % end of Outer Loop

You might also like