This post contains the TI-89 code for a program that calculates a gas' z-factor using the Hall-Yarborough correlation.
^^Note the Tr = T/T_critical
There are numerous correlations used for calculating the Z-factor, Hall Yarborough is a good one. If you're suffering from insomnia, PetroWiki has some great articles on different correlations used and their respective differences.
Besides being a long messy set of expressions, this problem requires an iterative approach to solve because assumed Z values must used to calculate Z. A while loop accomplishes this and calculates Z to an accuracy of 0.0001.
The accuracy is set 0.0001 rather 0 because (a) you really don't need more than 4 decimal places and (b) the accuracy is the stopping requirement for the loop and if it becomes infinitely small, your calculator will probably lock up. It's a numerical solution*.
*Depending on the mathematical background (or lack thereof) some people really struggle with the concept of a numerical solution from an empirical correlation vs. a theory based equation. This is understandable because from junior high to junior year of engineering, the only things ever dealt with fit into a neat theoretical box. In the "real" world of engineering, correlations and iterative solutions are the norm. Never thought you'd miss physics II?
ZFactor()
Prgm
ClrIO
Dialog
Title "enter data for Z-factor calculation" ©Using Hall-Yarborough Correlation
Request "tc [R]",tz,0
Request "pc [psia]",pz,0
Request "Temperature",T1,0
Request "Pressure",P1,0
EndDlog
expr(tz)→tz
expr(pz)→pz
expr(T1)→T1
expr(P1)→P1
T1/tz→tr
1/tr→t
© CONSTANT FUNCTIONS IN CORRELATION, A,B,C
(14.76*t-9.76*(t^2)+(4.58*t^3))→A
90.7*t-242.2*(t^2)+(42.2*(t^3))→B
1.18+(2.82*t)→C
0.245*((10.732*tz)/pz)*e^(-1.2*((1-t)^2))→b
0→zold
1→znew
© x and Z are the varying expressions
© x(Z_calc)
While Abs(Znew-Zold)>0.0001
(b*P1)/(4*(Znew)*10.732*T1)→x
((1+x+(x^2)-(x^3))/((1-x)^3))-(A*x)+(B*(x^C))→Zcalc
Znew→Zold
Zcalc→Znew
endwhile
Disp "Z-factor is: ",Zcalc
endPrgm
NOTE: This post isn't a TI-89 how-to, if you have questions, please leave comment and I'll elaborate.
There are numerous correlations used for calculating the Z-factor, Hall Yarborough is a good one. If you're suffering from insomnia, PetroWiki has some great articles on different correlations used and their respective differences.
Besides being a long messy set of expressions, this problem requires an iterative approach to solve because assumed Z values must used to calculate Z. A while loop accomplishes this and calculates Z to an accuracy of 0.0001.
The accuracy is set 0.0001 rather 0 because (a) you really don't need more than 4 decimal places and (b) the accuracy is the stopping requirement for the loop and if it becomes infinitely small, your calculator will probably lock up. It's a numerical solution*.
*Depending on the mathematical background (or lack thereof) some people really struggle with the concept of a numerical solution from an empirical correlation vs. a theory based equation. This is understandable because from junior high to junior year of engineering, the only things ever dealt with fit into a neat theoretical box. In the "real" world of engineering, correlations and iterative solutions are the norm. Never thought you'd miss physics II?
ZFactor()
Prgm
ClrIO
Dialog
Title "enter data for Z-factor calculation" ©Using Hall-Yarborough Correlation
Request "tc [R]",tz,0
Request "pc [psia]",pz,0
Request "Temperature",T1,0
Request "Pressure",P1,0
EndDlog
expr(tz)→tz
expr(pz)→pz
expr(T1)→T1
expr(P1)→P1
T1/tz→tr
1/tr→t
© CONSTANT FUNCTIONS IN CORRELATION, A,B,C
(14.76*t-9.76*(t^2)+(4.58*t^3))→A
90.7*t-242.2*(t^2)+(42.2*(t^3))→B
1.18+(2.82*t)→C
0.245*((10.732*tz)/pz)*e^(-1.2*((1-t)^2))→b
0→zold
1→znew
© x and Z are the varying expressions
© x(Z_calc)
While Abs(Znew-Zold)>0.0001
(b*P1)/(4*(Znew)*10.732*T1)→x
((1+x+(x^2)-(x^3))/((1-x)^3))-(A*x)+(B*(x^C))→Zcalc
Znew→Zold
Zcalc→Znew
endwhile
Disp "Z-factor is: ",Zcalc
endPrgm
NOTE: This post isn't a TI-89 how-to, if you have questions, please leave comment and I'll elaborate.