Use Monte Carlo approach for data of H&H section 4.2.2

In [1]:
import numpy as np
from scipy import stats

Same parameters and same function for P(V,T) as from problem number 3

In [2]:
def P(Vm,T):
    '''Return pressure as a function of measured quantities volume 
    and temperature'''
    return R*T/(Vm - b) - a/Vm**2
In [3]:
R = 8.3145
T_best = 298.0
alpha_T = 0.2
V_best = 2.000e-4
alpha_V = 0.003e-4
a = 1.408e-1
b = 3.913e-5
In [4]:
numExp = 1000     # Number of Monte Carlo "experiments"
Tvalues = stats.norm.rvs(T_best, alpha_T, size=numExp)
Vvalues = stats.norm.rvs(V_best, alpha_V, size=numExp)
simData = P(Vvalues,Tvalues)
Pbest = np.mean(simData)
αP = np.std(simData)
Pbest/1e6, αP/1e6
Out[4]:
(11.88161957994458, 0.020027213429308504)

So, this gives a result of

$$ P = 11.88 \pm 0.02\, \mbox{MPa}, $$

consistent with the results of the previous two problems.

In [6]:
%load_ext version_information
In [7]:
version_information numpy, scipy
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
scipy1.5.2
Thu Aug 06 16:14:39 2020 EDT
In [ ]: