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.
def P(Vm,T):
'''Returns pressure a function of measured volume and temperature'''
return R*T/(Vm - b) - a/Vm**2
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
Pbest = P(Vmbest,Tbest)
format(Pbest,'e')
or 11.882 MPa.
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.)
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)
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
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
%load_ext version_information
%version_information numpy