Ideal gas law with dimensional quantities and a physical constant¶
Maxima is a system for symbolic and numerical computation. Let's use the ezunits package of Maxima to handle dimensional quantities in a problem involving the ideal gas law, pV = nRT.
Inspired by this problem on Stackoverflow: https://stackoverflow.com/questions/64279773/ezunits-not-so-ez-ideal-gas Thanks to user Dux for posing the problem.
In addition to ezunits, we will make use of the physical_constants package, which includes the molar gas constant as %R
. Physical constants don't have an ordinary value, so they are carried around as symbols in calculations, until constvalue
pulls out the value of the physical constant.
This notebook has been composd in Jupyter using the maxima-jupyter kernel. For more about maxima-jupyter, see: https://github.com/robert-dodier/maxima-jupyter
Problem statement¶
Fuel cell vehicle, molecular hydrogen fuel. 2 tanks, T = 20°C, p_rel = 700 bar, m_tank = 6 kg. What is the volume of one tank? Solve for the tank volume assuming ideal gas law applies.
Solution¶
load (ezunits);
load (physical_constants);
Inspect value of molar gas constant %R.
%R, constvalue;
Declare unit conversion for bars. 1 bar = 100,000 pascals; this is a little less than one standard atmosphere, which is 101,325 pascals.
declare_unit_conversion (1`bar = 100000`Pa);
Convert from degrees Celsius to kelvins.
T: 20`degC `` K;
p_rel: 700`bar;
m_tank: 6`kg;
p: p_rel+1`bar;
Convert from bars to newtons per square meter.
p: p``N/m^2;
Molar mass of molecular hydrogen.
M_H_2:2*1.01`g/mol;
R: %R/M_H_2, constvalue;
Solve ideal gas law for volume. dimensionally
helps other functions handle dimensional quantities. Maxima prefers exact numbers to inexact, so a floating point value is replaced by a rational approximation.
dimensionally (solve (p*V = m_tank*R*T, V));
V: rhs(%[1]);
V
is the total volume of two tanks. Find the volume of one tank.
V_tank: V/2;
ezunits does not automatically convert units to basic units. Let's express V
in its basic units.
fundamental_units (V_tank);
V_tank `` fundamental_units(V_tank);
float (%);
Let's express the volume in more convenient units.
V_tank: % `` liter;
We don't really need so many digits in the result.
fpprintprec: 4;
V_tank;
Great, we'll let that be enough for now. Thanks for reading.
PS. This document was created as a Jupyter notebook using the maxima-jupyter kernel. It was converted to HTML via jupyter nbconvert --to html --template basic ezunits_ideal_gas_law_problem.ipynb
and then the MathJax preamble was pasted in by hand.