Checking H&H Section 4.4.2 -- functional approach

In [1]:
import numpy as np

Section 4.2.2 in Hughes & Hase is a worked example of the determination of pressure and its uncertainty using the van der Waals equation of state and the functional approach for determining uncertainties. Repeat these calculations for yourself, determining $P(\bar{V}_{\rm in},\bar{T})$, $\alpha_P^T$, $\alpha_P^V$, and $\alpha_P$. Identify the (slight) numerical errors made in the text.

In [2]:
def P(Vm,T):
    '''Returns pressure a function of measured volume and temperature'''
    return R*T/(Vm - b) - a/Vm**2

Data

In [3]:
R = 8.3145
Tbest = 298.0
alpha_T = 0.2
Vmbest = 2.000e-4
alpha_V = 0.003e-4
a = 1.408e-1
b = 3.913e-5

Calulate pressure

In [4]:
Pbest = P(Vmbest,Tbest)
format(Pbest,'e')
Out[4]:
'1.188201e+07'

or 11.882 MPa.

Uncertainties

In this solution, I create a numpy array (u) containing the uncertainties. (This is, perhaps, overkill with only two measured quantities with uncertainties, but this procedure can simplify calculations in more complicated problems.)

In [5]:
u = np.zeros(2)
u[0] = P(Vmbest + alpha_V, Tbest)
u[1] = P(Vmbest, Tbest + alpha_T)
u = u - Pbest

print('uncertainties in P due to uncertainties in V and T:',u,'\n')
print('fractional uncertainties in P due to uncertainties in V and T:',u/Pbest,'\n')
unc = np.sqrt(np.sum(u**2))
print('total uncertainty (in MPa):', unc/1.e6)
uncertainties in P due to uncertainties in V and T: [-18132.83430204  10336.91800833] 

fractional uncertainties in P due to uncertainties in V and T: [-0.00152607  0.00086996] 

total uncertainty (in MPa): 0.020872267575327286

So, the error in the pressure is

$$ \alpha_P = 0.02\, \mbox{MPa}. $$

(This is a little different from what is given in early printings of the text -- the cause appears to be in the calculation of the uncertainty in $P$ due to the volume.)

Version information

version_information is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python for more information and instructions for package installation.

version_information is installed on the linux network at Bucknell

In [6]:
%load_ext version_information
In [7]:
%version_information numpy
Out[7]:
SoftwareVersion
Python3.7.7 64bit [GCC 7.3.0]
IPython7.16.1
OSLinux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core
numpy1.18.5
Fri Aug 07 10:13:45 2020 EDT
In [ ]: