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?
Title "enter data for Z-factor calculation" ©Using Hall-Yarborough Correlation
Request "tc [R]",tz,0
Request "pc [psia]",pz,0
© CONSTANT FUNCTIONS IN CORRELATION, A,B,C
© x and Z are the varying expressions
Disp "Z-factor is: ",Zcalc
NOTE: This post isn't a TI-89 how-to, if you have questions, please leave comment and I'll elaborate.