# A Mathcad Utility Function for Air Pressure and Density

Quote of the Day

Fantasy is hardly an escape from reality. It’s a way of understanding it.

— Lloyd Alexander

## Introduction

Figure 1: Example of Moist Air Density
Versus Pressure and Temperature.
(Source)

I have some work to do that requires a model for air density as a function of altitude, temperature, and pressure. As usual, I will turn to the Wikipedia to provide me a working model. I will then check the results of my model against results published by other sources.

Figure 1 shows some typical air density data for different pressure and temperature values for air with a dew point of 10 °C. I am going to write some Mathcad programs that compute the density of air as a function of combinations of temperature, altitude, pressure, and relative humidity. I always write Mathcad versions of the software routines that I am creating so that I have results that I can use to verify my code.

I should note that humidity is a small effect, but it is one that I wanted to include in my modeling efforts.

## Background

### Definitions

Standard Atmosphere
The U.S. Standard Atmosphere is an atmospheric model of how the pressure, temperature, density, and viscosity of the Earth's atmosphere change over a wide range of altitudes or elevations (Source).
Relative Humidity
Relative humidity (abbreviated RH) is the ratio of the partial pressure of water vapor to the equilibrium vapor pressure of water at the same temperature. Relative humidity depends on temperature and the pressure of the system of interest (Source).
Dew Point
The dew point is the temperature at which the water vapor in a sample of air at constant barometric pressure condenses into liquid water at the same rate at which it evaporates (Source).
Lapse Rate
The lapse rate is defined as the rate at which atmospheric temperature decreases with an increase in altitude (Source).

### Objectives

In a sense, this is a simple post because I am just implementing empirical air pressure and density formulas from the Wikipedia. However, it is useful to see how to implement empirical relationships in Mathcad.

There are two key formulas: pressure versus altitude, sea level temperature, sea level pressure (Equation 1); and  density versus altitude, sea level pressure and sea level density  (Equation 2).

 Eq. 1 $\displaystyle p\left( {h,{{T}_{0}},{{p}_{0}}} \right)={{p}_{0}}\cdot {{\left( {1-\frac{L}{{{{T}_{0}}}}\cdot h} \right)}^{{\frac{{g\cdot M{{W}_{{air}}}}}{{{{R}_{d}}\cdot L}}}}}$ Eq. 2 $\displaystyle \rho \left( {h,{{p}_{0}},{{\rho }_{0}}} \right)={{\rho }_{0}}\cdot \frac{{p\left( {h,{{T}_{0}},{{p}_{0}}} \right)}}{{{{p}_{0}}}}\cdot \frac{{{{T}_{0}}}}{{{{T}_{0}}-L\cdot h}}$

where

• p is the estimated air pressure as measured at the altitude h.
• Rd is the universal gas constant.
• ρ0 is the air density at the reference level.
• MWair is the average molecular weight of an air molecule.
• g is the acceleration due to gravity at the Earth's surface.
• p0 is the air pressure as measured at our reference level (e.g. sea level).
• T0 is the air temperature as measured at our reference level (e.g. sea level).
• h is the change in altitude as measured from our reference level.
• L is the lapse rate, which is the assumed constant rate of temperature reduction with increase in altitude.

## Analysis

### Dry Air Characteristics

Figure 2 shows how I implemented the dry air pressure and density formulas from the Wikipedia. Nothing special here – just grind it out.

Figure 2: Derivation of Dry Air Pressure and Density Formulas.

### Humid Air Density Corrections

Figure 3 shows how I implemented the moist air model for density given in the Wikipedia. I parameterized the formula two ways:

• pressure, temperature, relative humidity

There is some debate about whether to use dew point or relative humidity. As far as I am concerned, they are equivalent measures because one can readily convert from one to the other using the formulas shown in Appendix A.

• height, sea level temperature, relative humidity

This model assume the characteristics of the 1976 US Standard Atmosphere, and specifically the 6.5 K/km lapse rate.

I also show how the model generates results similar to those from various web sources.

Figure 3: Model Including Humidity Correction.

### Calculation Example

In Figure 4, I use the formulas of Figures 2 and 3 to recreate Figure 1.

Figure 4: My Recreating Figure 1 Using the Formulas of Figure 3.

## Conclusion

All this work was performed using information from the Wikipedia. What an amazing resource for the working engineer! I was quickly able to develop automated routines for computing air pressure and density as functions of pressure, temperature, altitude, and relative humidity. I will now code these same formulas into a Java routine for use in some design tools I am building. I will use the Mathcad routines written above to generate test cases to validate my Java implementation.

## Appendix A: Converting Dew Point to Relative Humidity

Figure 5 shows my Mathcad implementation of formulas to convert between Relative Humidity (RH) and Dew Point Temperature (TD). I grabbed these formulas from this site.

Figure 5: Dew Point and Relative Humidity Conversion Formula (Source).

## Appendix B: Exponential Form of the Pressure Formula.

I occasionally see Equation 1 written in the form of an exponential. Figure 6 demonstrates how an exponential function can be used to approximate Equation 1.

Figure 6: Exponential Approximation to Equation 1.

This entry was posted in General Science. Bookmark the permalink.