Returns the pressure, volume, weight or temperature inside a gas given the other three parameters.

You're viewing an older version of this page (#382). View the current version.

View versions (1)

Interface

#include <codecogs/engineering/fluids/imperial/gaslaw.h>

using namespace Engineering::Fluids::Imperial;

Given four of the five parameters in the ideal gas law:

pV = wRT
(1)

this function is able to deduce the fifth one, where p is the pressure of gas, V is the volume, w is the weight, R is the individual gas constant and T is the absolute temperature in degrees Rankine.

In order to return the desired parameter, the function takes a target argument which can be PRESSURE, VOLUME, WEIGHT, GAS or TEMPERATURE correspondingly. The value of the desired parameter as argument in the function call is ingored, but a convenient way is to denote it by a null value.

You may notice that in the example code below we are considering carbon dioxide with gas constant R = 1130.

Example 1

#include <stdio.h>
#include <codecogs/engineering/fluids/imperial/gaslaw.h>

int main()
{
  double 
  p = Engineering::Fluids::Imperial::gaslaw
  (PRESSURE, 0, 1000, 850.3, 1130, 10),
  V = Engineering::Fluids::Imperial::gaslaw
  (VOLUME, 9608.39, 0, 850.3, 1130, 10),
  w = Engineering::Fluids::Imperial::gaslaw
  (WEIGHT, 9608.39, 1000, 0, 1130, 10),
  R = Engineering::Fluids::Imperial::gaslaw
  (GAS, 9608.39, 1000, 850.3, 0, 10),
  T = Engineering::Fluids::Imperial::gaslaw
  (TEMPERATURE, 9608.39, 1000, 850.3, 1130, 0);

  printf("    Pressure = %.2lf lb/ft^3\n", p);
  printf("      Volume = %.2lf ft^3\n", V);
  printf("      Weight = %.2lf lb\n", w);
  printf("Gas constant = %.2lf ft lb/slug deg.R\n", R);
  printf(" Temperature = %.2lf deg.R\n", T);

  return 0;
}

Output

Pressure = 9608.39 lb/ft^3
      Volume = 1000.00 ft^3
      Weight = 850.30 lb
Gas constant = 1130.00 ft lb/slug deg.R
 Temperature = 10.00 deg.R

Parameters

target
PRESSURE, VOLUME, WEIGHT, GAS or TEMPERATURE
pressure
pressure inside the gas (lb/ft² absolute)
volume
volume of gas (ft³)
weight
weight of gas (lb)
gas_constant
the individual gas constant (ft lb/slug °R)
temperature
absolute temperature of gas (°R)

Returns

The value of the desired parameter.

To add table with gas constants on http://www.engineeringtoolbox.com/individual-universal-gas-constant-d_588.html

References

The Engineering Division, Crane Co., "Flow of fluids through valves, fittings, and pipe", Chicago, 1957

GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

target
pressure
volume
weight
gas_constant
temperature
Result