import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
residue_R = 0.044
ofunc=0.001
measured_R = np.array([21.754,21.751,21.75,21.749,21.753,21.754,21.754,21.753,21.751,21.756])
r_m_true = measured_R - residue_R
count = len(r_m_true)
sample_mean = np.mean(r_m_true)
SD = np.std(r_m_true)
exp_SD = SD/np.sqrt(count)
u1=exp_SD
DoF = count-1
print("Number of samples: " ,str(count))
print("Mean of samples:" , sample_mean)
print("Standard Deviation of samples: " ,"{:.2e}".format(SD))
print("\nExperimental Standard Deviation u_1 of samples:", "{:.2e}".format(exp_SD))
print("\nDegrees of freedom of samples", str(DoF))
plt.figure(figsize=(16,8))
plt.hist(r_m_true, bins=5)
plt.xlabel("Measured resistances [Ohm]")
plt.ylabel("Number of occurances")
#From Appendix
u2_a = 0.05/100 #reading error
u2_b = 0.008/100 #range error
#Standard Uncertianty:
u2_st = np.sqrt(u_2_a**2+u_2_b**2)
print("Standard Uncertianty: " + str(u2_st*100) + "%")
#Uncertainty value:
u2_value = u2_a * sample_mean + u2_b * 100
print("\nUncertainty value for u2: " + str(u2_value))
DMM_res = 0.00045/np.sqrt(3)
print("{:.2e}".format(DMM_res))
u_1 = exp_SD
print(u_1)
u_2 = u2_value
print(u_2)
u_3 = 0.0005
print(u_3)
u_total = np.sqrt((u_1**2)+(u_2**2)+(u_3**2))
print("Combined Uncertianty:","{:.2e}".format(u_total))
# Welch-Satterthwaite formula:
v_eff = u_total**4/((1**4 * u2_st**4)/(DoF))
print("\nv_eff is: " ,"{:.2e}".format(v_eff))