View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Compressibility Factor Calculator

4.7 | 3 ratings Rate this file 33 Downloads (last 30 days) File Size: 3.11 KB File ID: #35874 Version: 1.2
image thumbnail

Compressibility Factor Calculator


Chad Greene (view profile)


28 Mar 2012 (Updated )

Calculates the compressibility factor of a gas using the Van der Waals equation of state.

| Watch this File

File Information

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:
carbon dioxide
carbon monoxide
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);

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 =


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.


Unit Converters inspired this file.

This file inspired Minnaert Bubble Models, Water Sound Speed Calculator, Sulfur Hexafluoride Property Lookup, and Compressibility Factor Calculator (Exact).

Required Products MATLAB
MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
06 May 2016 Jon

Jon (view profile)

21 Jun 2013 Cho

Cho (view profile)

06 Nov 2012 Chad Greene

Chad Greene (view profile)

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!

Comment only
05 Nov 2012 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!

06 Nov 2012 1.2

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

Contact us