In [21]:
import numpy as np
A_det = np.matrix('10 0; -2 100') #A-matrix
B_det = np.matrix('1 10') #B-matrix
f = np.matrix('1000; 0') #Functional unit vector f
g_LCA = B_det * A_det.I * f
print("The deterministic result is:", g_LCA[0,0])
In [19]:
N = 1000 #Sample size
CV = 0.05 #Coefficient of variation (CV = sigma/mu)
import random
A1 = [random.gauss(A_det[0,0], CV*A_det[0,0]) for i in range(N)]
A3 = [random.gauss(A_det[1,0], CV*A_det[1,0]) for i in range(N)]
A4 = [random.gauss(A_det[1,1], CV*A_det[1,1]) for i in range(N)]
B1 = [random.gauss(B_det[0,0], CV*B_det[0,0]) for i in range(N)]
B2 = [random.gauss(B_det[0,1], CV*B_det[0,1]) for i in range(N)]
As = [np.matrix([[A1[i], 0],[A3[i], A4[i]]]) for i in range(N)]
Bs = [np.matrix([[B1[i], B2[i]]]) for i in range(N)]
f = np.matrix('1000; 0')
gs = [B * A.I * f for A, B in zip(As, Bs)]
g_list =[g[0,0] for g in gs]
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
plt.hist(g_list,20)
plt.title("Histogram")
plt.xlabel("kg CO2")
plt.ylabel("Frequency")
fig = plt.gcf()
In [22]:
import statistics as stats
var_g = stats.variance(g_list)
print("The output variance equals:", var_g)
In [ ]: