Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

clear

clc

% Input data
P = input(' Input the vector of pressure range (Pa) = ');
T = input(' Input temperature (K) = ');
R = 8314; % Gas constant (J/kmol.K)
Tc = input(' Critical temperature (K) = ');
Pc = input(' Critical pressure (Pa) = ');
omega = input(' Acentric factor = ');

% Constants of Soave-Redlich-Kwong equation of state


a = 0.4278 * R^2 * Tc^2 / Pc;
b = 0.0867 * R * Tc / Pc;
sc = [-0.15613, 1.55171, 0.48508];
s = polyval(sc,omega);
alpha = (1 + s * (1 - sqrt(T/Tc)))^2;
A = a * alpha * P / (R^2 * T^2);
B = b * P / (R * T);

for k = 1:length(P)
% Defining the polynomial coefficients
coef = [1, -1, A(k)-B(k)-B(k)^2, -A(k)*B(k)];
v0(k) = R * T / P(k); % Ideal gas specific volume
vol(k) = NRpoly(coef , 1) * R * T / P(k); % Finding the
root
end

% Show numerical results


fprintf('\nRESULTS:\n');
fprintf('Pres. = %5.2f Ideal gas vol. =%7.4f',P(1),v0(1));
fprintf(' Real gas vol. =%7.4f\n',vol(1));
for k=10:10:length(P)
fprintf('Pres. = %5.2f Ideal gas vol. =%7.4f',P(k),v0(k));
fprintf(' Real gas vol. =%7.4f\n',vol(k));
end

% plotting the results


loglog(P/1000,v0,'.',P/1000,vol)
xlabel('Pressure, kPa')
ylabel('Specific Volume, m^3/kmol')
legend('Ideal','SRK')

You might also like