File Exchange

image thumbnail

Compressibility Factor Calculator

version 1.2.0.0 (3.11 KB) by Chad Greene
Calculates the compressibility factor of a gas using the Van der Waals equation of state.

20 Downloads

Updated 06 Nov 2012

View License

Approximates compressibility factor (commonly denoted Z) of gas at a given temperature and absolute pressure. Calculated by Van der Waals equation of state.

Z = PV/(RT)

Solves compressibility factor for the following gases:
air
ammonia
argon
butane
carbon dioxide
carbon monoxide
methane
ethane
helium
hydrogen
neon
nitrogen
oxygen
propane
sulfur dioxide
sulfur hexafluoride

Note: The Van der Waals equation is an improvement of the ideal gas law, above the critical temperature, and is also qualitatively reasonable below the critical temperature, but it is almost never appropriate for rigorous quantitative calculations. (Paraphrased from T.L. Hill, Statistical Thermodynamics, Addison-Wesley, Reading (1960))

**********************************************************
Example 1: Find the compressibility factor of methane at 280 K and 20 bar:

Z = compressibility('methane',280,20)
Z = 0.951

The above example shows that methane at 280 K and 20 bar deviates from the ideal gas law by approximately 4.9%.

**********************************************************
Example 2: Calculate Z for a range of pressures with constant temperature:

T = 195; % [°K]
P = 1:100; % [bar]

Z = compressibility('sf6',T,P);

plot(P,Z)
box off
xlabel('hydrostatic pressure (bar)')
ylabel('compressibility factor {\it Z}')
title(['SF_6 at ',num2str(T),' K'])

**********************************************************
Example 3: Calculate Z for an array ofCalculate Z for arrays of simultaneously-varying pressure and temperature values.

compressibility('methane',[280 300 350],[1 10 20])

ans =
0.9976
0.9802
0.9755

**********************************************************

This function can be modified to solve for any gas you wish if you know its critical temperature Tc and critical pressure Pc. Do this by adding a case in the following form

case 'your gas'
Tc = YourGasTc; % [K] critical temperature
Pc = YourGasPc; % [bar] critical pressure

Above you must enter the name of 'your gas' and the correct values for YourGasTc and YourGasPc.

**********************************************************

I am not a thermodynamicist, so I can not fully attest to the accuracy of this function, or the appropriateness of using it for any given gas (including the gases listed above).

Use of this function may benefit from use of unit conversion functions such as the bundle listed below.

Cite As

Chad Greene (2020). Compressibility Factor Calculator (https://www.mathworks.com/matlabcentral/fileexchange/35874-compressibility-factor-calculator), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (13)

It does not seem to match for Nitrogen and AIr. See ea: https://www.peacesoftware.de/einigewerte/calc_luft.php7

This is a useful function that does exactly what it advertises. However, while it is a valuable tool that allows the user to quickly gather information about the compressibility of the 16 gases that are tabulated in it, there are still many improvements that could be made to increase the usefulness of the code. Including unit system conversions and adding more ‘cases’ for more common gases would make the function applicable to a wider range of problems to make the code 5/5, but it still successfully does what it says it will, so for that the code gets a 4/5.

We rate 3.5/5 stars for the original code. This is because the code is limiting in that it only uses 16 gases out of the hundreds listed in the Air Liquide encyclopedia that it references. It uses the Van Der Waals equation instead of more accurate equations like Redlich-Kwong Equation of State or the Dieterici Equation of State. Similarly the input of the gas name is limited in that if someone doesn’t capitalize the name correctly or misspells it, the code won’t run. However, it does calculate the compressibility factor and runs as a complete code. Therefore it’s slightly above average, but needs significant improvement to be 5/5 stars.

Maura Devi

Excellent job, Chad. The only thing I would change would be to update the critical values from the Air Liquide website as half of them were not accurate. I understand that the code was last updated in 2012. Another thing is that the critical values differ in significant figures, which dampens the accuracy of the calculations quite a bit.

Tung Nguyen

Jon

Cho

Chad Greene

Excellent catch, Rebecca! I've updated the function to include Newton's corrections for the quantum gases as you suggested. The new version now also accepts arrays as inputs. The improved function will be up as soon as the File Exchange administrators approve it. Thanks for sharing your expertise!

Rebecca

As a Chemical Engineering student, I've found this to be a great help. My only issue (after only using this a few times) is that Newton's Corrections weren't taken into consideration for helium and hydrogen. (Tc adjusted = Tc + 8K ; Pc adj = Pc + 8.106 bar) Otherwise, choice function!

Updates

1.2.0.0

Included Newton's corrections for quantum gases (Thanks for the tip, Rebecca!); updated the function to accept array inputs, included neon.

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux

compressibility v2/