Hello, ı have a problem with Z factor, although ı have different Pr values which plays as a variable in finding Z factor,ı still have the same value for Z factor as 1.0001 each time .Can anyone help me ı will be grateful

yH2S=0;
yCO2 =0;
yN2=0;
N2=input(' N2 enter:');
CO2=input('CO2 enter:');
H2S=input('H2S enter:');
Gg=input('Gg enter:');
T=60;
P=zeros(1,100);
for i=1:100
P(1)=0;
P(i+1)=P(i)+100;
yN2 = N2 / 100;
yCO2 = CO2 / 100;
yH2S = H2S / 100;
cGg = (Gg - 0.9672 * yN2 - 1.5197 * yCO2 - 1.1768 * yH2S) / (1 - yN2 - yCO2 - yH2S);
Tpc = 168 + 325 * cGg - 12.5 * cGg ^ 2;
CorrTpc = Tpc - 80 * yCO2 + 130 * yH2S - 250 * yN2;
Ppc = 677 + 15 * cGg - 37.5 * cGg ^ 2;
CorrPpc = Ppc + 440 * yCO2 + 600 * yH2S - 170 * yN2;
Tr = (T + 460) / CorrTpc;
Pr = P / CorrPpc;
a = 0.064225133;
b = 0.53530771 * Tr - 0.61232032;
c = 0.31506237 * Tr - 1.0467099 - 0.57832729 / Tr ^ 2;
d = Tr;
e = 0.68157001 / Tr ^ 2;
f = 0.68446549;
g = 0.27 * Pr;
rho = 0.27 * Pr / Tr ;
rhoold = rho;
for i = 1:100
frho = a * rho .^ 6 + b * rho .^ 3 + c * rho .^ 2 + d * rho + e * rho .^ 3 .* (1 + f * rho .^ 2) .* exp(-f * rho .^ 2) - g;
dfrho = 6 * a * rho .^ 5 + 3 * b * rho .^ 2 + 2 * c * rho + d + e * rho .^ 2 .* (3 + f * rho .^ 2 .* (3 - 2 * f * rho .^ 2)) .* exp(-f * rho .^ 2);
rho = rho - frho / dfrho;
test = abs((rho - rhoold) / rho);
if test < 0.0001
rhoold = rho;
ZFactor = 0.27 * Pr / rho / Tr;
end
end
Zm=ZFactor;
MW = 28.97 * Gg;
a = (9.4 + 0.02 * MW) * (T + 460) ^ 1.5 / (209 + 19 * MW + (T + 460)) / 10000;
b = 3.5 + 986 / (T + 460) + 0.01 * MW;
c = 2.4 - 0.2 * b;
rho = P * MW / Zm / 10.73 / (T + 460);
Ug = a * exp(b * (rho / 62.4) .^ c);
mP1 = 0;
Pold = 0;
Xold = 0;
Pstep = P / 20;
for j=0:20
Pnew = Pold + Pstep;
Pr = Pnew / Ppc;
Xnew = 2 * Pnew / Zm / Ug;
mP1 = mP1 + (Xold + Xnew) / 2 * Pstep;
Pold = Pnew;
Xold = Xnew;
end
end

Answers (3)

You seem to just keep reassigning to ZFactor inside a for loop.
If you want multiple answers you need someting like:
ZFactor(i) = 0.27 * Pr / rho / Tr;
You also have nested loops that both use 'i' as the loop variable. To be honest I have no idea what the behaviour is when this happens, but I doubt it will be what you want. Even if it is don't do it as it isn't good practice!
If you substitute ‘rho’ into ‘ZFactor’:
rho = 0.27 * Pr / Tr ;
ZFactor = 0.27 * Pr / rho / Tr;
and do some simple algebra, you will see that:
ZFactor = 1
regardless of the values of the other variables.
yes I am also aware of this part but in reality there must be such number like Z=1.2 or 1.4 something

Categories

Find more on MATLAB Support Package for LEGO MINDSTORMS EV3 Hardware in Help Center and File Exchange

Asked:

on 3 Nov 2014

Commented:

on 3 Nov 2014

Community Treasure Hunt

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

Start Hunting!