Hi, I keep getting y as a 3x3 matrix, but its supposed to come out as a 3x1 matrix. Could someone please find my mistake. I think Im missing a matrix decimal divide or multipl
Show older comments
% Take home problem 2
% Water (1), Acetone (2), Methanol (3)
R = 83.14; % bar cm^3 mol^-1 K^-1
P = 2; %bars
x = [0.35; 0.25; 0.40];
V = [18.07; 74.05; 40.73]; % cm^3/mol
a = [0 6062.5 1965.9; 1219.5 0 -677.8; 449.6 2441.4 0]; % J/mol
w = [0.345; 0.307; 0.564];
Tc =[647.1; 508.2; 512.6]; % K
Pc = [220.55; 47.01; 80.97]; % bar
Zc = [0.229; 0.233; 0.224];
Vc = [55.9; 209; 118]; % cm^3/mol
% Antoine’s equation constants (with these constants P is in kPa and T in Celsius
A = [16.3872; 14.3145; 16.5785];
B = [3885.70; 2756.22; 3638.27];
C = [230.170; 228.060; 239.500];
N = max(size(w)); % number of components
phi = ones(N);
Tsat = B./(A - log(100*P)) - C + 273.15
T = Tsat'*x
Psat = exp(A-B./(T-273.15+C))/100;
gamma = wilson(x, a, V, R*T);
% Let’s simply choose Pjsat as Psat(1)
s = 0; % initialize summation
for i=1:N
s = s + ((gamma(i)*x(i)/phi(i))*(Psat(i)/Psat(1)));
end
Pjsat = P/s;
T = B(1)/(A(1) - log(100*Pjsat)) - C(1) + 273.15; % temperature in Kelvins
Psat = exp(A-B./(T-273.15+C))/100;
y= x.*gamma.*Psat./(phi.*P);
[BB d] = virial2(T, Tc, Pc, Zc, Vc, w); %virial coefficients needed to calculate fugacity coefficients
phi = virialcoeff(BB, d, T, y, P); % fugacity coefficients
gamma = wilson(x, a, V, R*T);
s = 0;
for i=1:N
s = s + ((gamma(i)*x(i)/phi(i))*(Psat(i)/Psat(1)));
end
Pjsat = P/s;
T = B(1)/(A(1) - log(100*Pjsat)) - C(1) + 273.15;
er1 = 1; % initialize error to a value large enough that it can’t be satisfied the first iteration
while er1 > 1e-3
Psat = exp(A-B./(T-273.15+C))/100;
y=x.*gamma.*Psat./(phi.*P);
[BB d] = virial2(T, Tc, Pc, Zc, Vc, w); %virial coefficients needed to calculate fugacity coefficients
phi = virialcoeff(BB, d, T, y, P); % fugacity coefficients
gamma = wilson(x, a, V, R*T);
s = 0; % initialize summation
for i=1:N
s = s + ((gamma(i)*x(i)/phi(i))*(Psat(i)/Psat(1)));
end
Pjsat = P/s;
Tnew = B(1)/(A(1)-log(100*Pjsat))-C(1)+273.15; % T in K
er1 = abs(1-Tnew/T)
T = Tnew;
end
T
y
2 Comments
the cyclist
on 22 Jul 2022
It's difficult to debug this, without access to the subfunctions (e.g. wilson). I recommend setting breakpoints so that you can see what shape/size your other variables are.
Tony Mei
on 22 Jul 2022
Accepted Answer
More Answers (0)
Categories
Find more on Thermal Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!