Undefined function or variable "C".Error in line

1 次查看(过去 30 天)
Hi
I've been given a function by my professor that calculates PT flash for non -ideal systems. I'm trying to use it to simulate an experiment. But continously get error.
I think it may be the way i've set my input up.
The function is below:
function[Xeq, Yeq, alphaV, Fl, Fv]=PTFLASH_VLE_Wilson(C,MW,rhoL,BIP,P,T,Z)
%this is a function that calculates PT flash for non -ideal systems where K
%cannot be explicit since it depends on X which is also a variable
c=length(Z);
for i=1:c
Ps=exp((C(i,1))+(C(i,2)/T)+(C(i,3)*log(T))+(C(i,4)*T^C(i,5)));
end
% validating the possibility of having VLE
[PB,y]=PB_VLE_Wilson(Z,C,MW,rhoL,T,BIP);
[PD,x]=PD_VLE_wilson (C,MW,rhoL,BIP,T,Z);
% checking if there is VLE
if P<=PD %% y here represents the mole fraction of componenets
Xeq=0;
Yeq=y;
alphaV=1;
Fl=0;
Fv=P*Z;
elseif P>=PB %% x here represents the mole fraction of components
Xeq=x;
Yeq=0;
alphaV=0;
[gamma,a]=ACTIVITY_WILSON(MW,rhoL,BIP,T,Xeq);
Fl=Ps.*Xeq.*gamma;
Fv=0;
else
Xeq=(x+y)/2 ; % first guess on x
[gamma,a]=ACTIVITY_WILSON(MW,rhoL,BIP,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
Xeq=0;
Yeq=0;
alphaV=0;
Fl=0;
Fv=0;
disp("bad initial guess")
else %supposedly good initial guess
Fl=zeros(1,c); % trick to enter the while cycle at the begininng
Fv=Fl+1;
iter=0; % initialization of iteration count
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,a]=ACTIVITY_WILSON(MW,rhoL,BIP,T,Z); %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
The input:
T=320;
Z=[0.1 0.9];
P=1.5E04
MW=[60.09 100.16];
rhoL=[803 802];
T=303.15;
BIP=[196.250 386.133;196.250 386.133];
C=[88.1834 -8498.6 -9.0766 8.330e18 6;153.23 -10055 -19.488 1.6426e5 2];
C1=[88.134 153.23];
C2=[-8498.6 -10055];
C3=[-9.0766 -19.488];
C4=[8.330e18 1.6426e5];
C5=[6 2];
C = [C1' C2' C3' C4' C5'];
Tc=[301 263];

回答(2 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-5-22
编辑:KALYAN ACHARJYA 2019-5-22
I didnot find the same error, in my case the error is expected that I dont have PB_VLE_Wilson function file.
P =
15000
Undefined function or variable 'PB_VLE_Wilson'.
Why you are considering two C
C=[88.1834 -8498.6 -9.0766 8.330e18 6;153.23 -10055 -19.488 1.6426e5 2];
......
C = [C1' C2' C3' C4' C5'];
Is this both are same, if not in this case peivious C is replaced by later C, whch pass to the finction.
  3 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2019-5-22
I am tired now there are more functions
Undefined function or variable 'ACTIVITY_WILSON'.

请先登录,再进行评论。


Chinaemerem Valentine Nwobi
Hi Kalyan,
sorry for the inconveniences attached to this. please find enclosed the requested script
function [gamma,a]=ACTIVITY_WILSON(MW,rhoL,BIP,T,Z)
%This program calculates the activity coefficients (gamma) and the
%activities (a) of each component of a mixture of c components using the
%Wilson model.
%INPUT PARAMETERS: MW: vector (1xc) reporting the molecular weights of the
%c components; rhoL, vector (1xc) reporting the liquid density of the c
%pure components at temperature T; BIP is a matrix cxc reporting the energy
%interaction parameters (BIP(i,j)=lambda_ij-lambda_ii, J/mol). The energy
%interaction parameters are temperature independent; T: temperature of the
%system; x vector (1xc) reporting the mole fractions of the components of
%the mixture.
%OUTPUT PARAMETERS: gamma: vector 1xc reporting the activity
%coefficients of the components of the mixture; a: vector 1xc reporting the
%activities of the components of the mixture.
%Unless otherwise stated, all input/output parameters are expressed
%according to MKS.
R=8.314;
c=length(Z);
%Molar volumes of the pure liquid components composing the mixture
Vl=1./((rhoL*1000)./MW);
%Lambda terms (dimensionless) of the Wilson formula
for i=1:c
for j=1:c
Lambda(i,j)=(Vl(j)/Vl(i))*exp(-BIP(i,j)/(R*T));
end
end
for i=1:c
for j=1:c
A=sum(Z.*Lambda(j,:));
C(j)=Z(j)*Lambda(j,i)/A;
end
lngamma(i)=1-log(sum(Z.*Lambda(i,:)))-sum(C);
gamma(i)=exp(lngamma(i));
a(i)=gamma(i)*Z(i);
end
end

Community Treasure Hunt

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

Start Hunting!

Translated by