CLC
CLC
%This script solves the Peng Robion cubic using T(K), P(MPa) from workspace.
%This script illustrates
% how a script leaves all variables in the workspace
% solving polynomials for roots
% sorting vectors
% eliminating imaginary roots
%*****************Input section**************************
%Set the ID from ../Props/props.mat. Use 'run ../Props/propsTableBrowse'
to preview.
propsRow = 67; %enter the row number from the table, not the ID number
%*****************End of input section********************
%{
Specify T(K) and P(MPa) in the workspace by entering into
the workspace numerical values calculated from the critical
properties (Tc, Pc) of the compound you have specified.
To try out the calculator, try the pairs
T = 0.7 * Tc, P = 0.5 * Pc
T = 0.7 * Tc, P = 0.2 * Pc
and T = 1.5 * Tc, P = 0.5 * Pc
(where Tc and Pc values are given below)
For propane these pairs of values are:
T = 259; P = 2.13;
T = 259; P = 0.85;
T = 555; P = 2.13;
%}
name = props{propsRow,2};
Tc = props{propsRow,4};
Pc = props{propsRow,5};
w = props{propsRow,6};
err = 0;
if(isempty(name))
disp('Compound name not found.')
err=1;
end
if(isempty(Tc))
disp('Critical Temperature not found.')
err=1;
end
if(isempty(Pc))
disp('Critical Pressure not found.')
err=1;
end
if(isempty(w))
disp('Acentric factor not found.')
err=1;
end
if(err == 1)
disp('Terminating. Check props database row and folder path.')
return;
end
if (not(exist('P')) | not(exist('T')))
if not(exist('P')) disp('Please specify P(MPa) and re-run preos.')
end
if not(exist('T')) disp('Please specify T(K) and re-run preos.')
end
return
end
R = 8.314472; %MPa.cm^3/mol.K
b = 0.0777960739*R*Tc/Pc;
ac = 0.4572355289*(R*Tc)^2/Pc;
kappa = 0.37464+1.54226*w-0.26992*w^2;
%calculate conditions
Tr = T/Tc;
Pr = P/Pc;
alpha = (1+kappa*(1-sqrt(Tr)))^2;
%calculate dimensionless parameters
A = ac*alpha*P/(R*T)^2;
B = b*P/R/T;
%determine cubic coefficients and solve cubic
a2 = -(1-B);
a1 = A-3*B^2-2*B;
a0 = -B*(A-B-B^2);
% display results
sprintf('Z= %f %f', Z)
V = Z*R*T/P; %cm^3/mol
sprintf('V(cm^3/mol)= %f %f', V)
% a constant that will be useful in formulas
sq = sqrt(2);