'Writing For loop for summation of B in Matlab
the summation to be written in a for loop is here
TCPC = csvread ( 'tcpc.csv' ) ;
TCPC ( : , 3) = TCPC ( : , 3 ) * (100000); %unit conversion
TCPC ( : , 5) = TCPC ( : , 5 ) * (1e-6); %unit conversion
%------------------------------------------------------------------------
% Within the outer loop we calculate Bii's Psat for all components
for i = 1 : n
W(i,i) = TCPC (SP(i),1) ;
TC(i,i) = TCPC (SP(i),2);
PC(i,i) = TCPC (SP(i),3);
ZC(i,i) = TCPC (SP(i),4);
VC(i,i) = TCPC (SP(i),5);
TR(i,i) = T/TC(i,i);
Bi(i,i) = (R*TC(i,i)/PC(i,i))*((.083-(.422/(TR(i,i)^(1.6))))+(W(i,i)*(.139-
((.0172/(TR(i,i)^4.2))))));
phisat(i) = exp((Bi(i,i)*P)/(R*T)) ;
for j = i+1 : n % Within the inner loop we calculate Bij's (mixed coefficients)
W(i,j) = (TCPC (SP(i),1) + TCPC (SP(j),1)) / 2 ;
TC(i,j) = sqrt((TCPC (SP(i),2) * (TCPC (SP(j),2)))) ;
ZC(i,j) = ((TCPC (SP(i),4) * (TCPC (SP(j),4))))/2 ;
VC(i,j) = (((TCPC (SP(i),5)^(1/3) * (TCPC (SP(j),5)^(1/3))))/2)^(3) ;
PC(i,j) = ((ZC(i,j) * R * (TC(i,j)))/VC(i,j)) ;
Bi(i,j) = ((R*TC(i,j))/PC(i,j))*((.083-(.422/(TR(i,i)^(1.6))))+(W(i,j)*(.139-
((.0172/(TR(i,i)^4.2))))));
Bi(j,i)=Bi(i,j); % as Bij=Bji we write the inner loop for j = i+1 : n and assigned
the values to rest
end
end
for i = 1 : n
B(i,i) = ((X(i))^2)*Bi(i,i);
a = sum(B(i,i));
for j = i+1 : n
B(i,j) = X(i)*X(j)*Bi(i,j);
B(j,i) = B(i,j);
b = sum(B(i,j)); c = sum(B(j,I));
end
end
Bfinal = a+b+c
%------------------------------------------------------------------------
% Having calculated all the second virial coefficients,
% we calculate the fugacity coefficients for all the components of the mixture
% use phi bar 1-3 and phi 1-3
for i = 1:n
for j = i+1 : n
phi(i,j) = exp((((-Bfinal+2*X(i)Bi(i) + 2X(j)))P)/(RT));
end
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
