Loading [MathJax]/jax/output/HTML-CSS/jax.js

Sunday, October 11, 2020

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
In [1]:
load (ezunits);
Out[1]:
 /home/robert/maxima/maxima-code/share/ezunits/ezunits.mac 
In [2]:
load (physical_constants);
Out[2]:
 /home/robert/maxima/maxima-code/share/ezunits/physical\_constants.mac 

Inspect value of molar gas constant %R.

In [3]:
%R, constvalue;
Out[3]:
1039309125000JmolK

Declare unit conversion for bars. 1 bar = 100,000 pascals; this is a little less than one standard atmosphere, which is 101,325 pascals.

In [4]:
declare_unit_conversion (1`bar = 100000`Pa);
Out[4]:
done

Convert from degrees Celsius to kelvins.

In [5]:
T: 20`degC `` K;
Out[5]:
586320K
In [6]:
p_rel: 700`bar;
Out[6]:
700bar
In [7]:
m_tank: 6`kg;
Out[7]:
6kg
In [8]:
p: p_rel+1`bar;
Out[8]:
701bar

Convert from bars to newtons per square meter.

In [9]:
p: p``N/m^2;
Out[9]:
70100000Nm2

Molar mass of molecular hydrogen.

In [10]:
M_H_2:2*1.01`g/mol;
Out[10]:
2.02gmol
In [11]:
R: %R/M_H_2, constvalue;
Out[11]:
4.116075247524752JgK

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.

In [12]:
dimensionally (solve (p*V = m_tank*R*T, V));
rat: replaced -7239.764752871287 by -1223527483/169001 = -7239.764752871285
Out[12]:
[V=122352748311846970100000m2kgJgN]
In [13]:
V: rhs(%[1]);
Out[13]:
122352748311846970100000m2kgJgN

V is the total volume of two tanks. Find the volume of one tank.

In [14]:
V_tank: V/2;
Out[14]:
122352748323693940200000m2kgJgN

ezunits does not automatically convert units to basic units. Let's express V in its basic units.

In [15]:
fundamental_units (V_tank);
Out[15]:
m3
In [16]:
V_tank `` fundamental_units(V_tank);
Out[16]:
122352748323693940200m3
In [17]:
float (%);
Out[17]:
0.05163883561249133m3

Let's express the volume in more convenient units.

In [18]:
V_tank: % `` liter;
Out[18]:
51.63883561249133liter

We don't really need so many digits in the result.

In [19]:
fpprintprec: 4;
Out[19]:
4
In [20]:
V_tank;
Out[20]:
51.64liter

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.

No comments:

Post a Comment