matrix manipulation for Ps(i)

1 次查看(过去 30 天)
%%
%please am trying to run this script with the fuction file and input data
%but it keeps giving errors about undefined function and so I need help in
%how I can arrange my C to get Psi in the code file for two components i.e
%z input
%%
function [xeq,yeq,alphaV,fL,fV] = PTFLASH_VLE_NRTL(C, BIP, alpha, P, T, z)
%The funtion PTFLASH_VLE_WILSON calculates VAPOR and LIQUID COMPOSITION,
%VAPOR FRACTION AND LIQUID AND VAPOR FUGACITIES.
%considering deviation from the ideal behavior using WILSON model
%All input/output data are expressed in SI.
%T[K], C[according to equation]
%length of the vector
m=length(z);
%vapor pressure calculation
for i=1:m
Ps(i)=exp(C(i,1)+C(i,2)/T+C(i,3)*log(T)+C(i,4)*T^(C(i,5)));
end
%calling PB and PD equations
[PB, ~] = PB_VLE_NRTL(C, BIP, alpha, T, z);
[PD, x] = PD_VLE_NRTL(C, BIP, alpha, T, z);
if P<=PD
xeq=0;
yeq=z;
alphaV=1;
fL=0;
fV=P*z;
elseif P>=PB
xeq=z;
yeq=0;
alphaV=0;
[gamma,~]=ACTIVITY_NRTL(BIP,alpha,T,xeq);
fL=Ps.*xeq.*gamma;
fV=0;
else
xeq=(x+z)/2; %First guess on x
[gamma,~]=ACTIVITY_NRTL(BIP,alpha,T,xeq); %First guess on gamma
K=(Ps.*gamma)/P; %First guess on K
psi_0=sum(z.*(K-1));
psi_1=sum(z.*(K-1)./K);
if psi_0*psi_1>=0 %Bad initial guess
disp('bad initial guess-BIG PROBLEM')
else %Good initial guess
fL=zeros(1,m);
fV=fL+1;
iter=0;
while max( abs((fV-fL)./fV))>0.00001 && iter<10000 && psi_0*psi_1<0
[ alphaV ] = RACHFORDRICE_BISECT( K,z );
xeq=z./((1-alphaV)+alphaV*K);
yeq=K.*xeq;
[gamma,~]=ACTIVITY_NRTL(BIP,alpha,T,xeq); %Gamma new guess
K=(Ps.*gamma)/P;
psi_0=sum(z.*(K-1));
psi_1=sum(z.*(K-1)./K);
fV=P*yeq;
fL=Ps.*xeq.*gamma;
iter=iter+1;
end
end
end
end
%% Input data
z=[0.1 0.9];
C1=[88.134 153.23];
C2=[-8498.6 -10055];
C3=[-9.0766 -19.488];
C4=[8.330e18 1.6426e5];
C5=[6 2];
RhoL=[803 802];
MW=[60.09 100.16]
MW =
60.0900 100.1600
P=0.5e6;
T=373.15;
BIP=[64.59 538.538];

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by