import numpy as np
from scipy import stats
Same parameters and same function for P(V,T) as from problem number 3
def P(Vm,T):
'''Return pressure as a function of measured quantities volume
and temperature'''
return R*T/(Vm - b) - a/Vm**2
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
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
So, this gives a result of
$$ P = 11.88 \pm 0.02\, \mbox{MPa}, $$consistent with the results of the previous two problems.
%load_ext version_information
version_information numpy, scipy