def wavgstd(values, asufloat=False): """ Returns the weighted average and standard deviation. values, weights -- Numpy ndarrays with the same shape. """ values, weights = checkufloat(values) if weights and asufloat is True: weights = numpy.array(weights) values = numpy.array(values) average = numpy.average(values, weights=weights) variance = numpy.dot(weights, (values - average) ** 2.0) / weights.sum() # Fast and numerically precise if asufloat: ufstdev = uncertainties.sqrt(variance) ufvalue = ufloat((average, ufstdev)) else: ufvalue = (average, uncertainties.sqrt(variance)) else: if asufloat: if isinstance(values[0], uncertainties.UFloat): ufvalue = numpy.mean(values) else: ufvalue = ufloat(str(numpy.mean(values))) # assign minimal error if no std deviation elif asufloat is False: ufvalue = (numpy.mean(values), numpy.std(values, ddof=1)) else: raise NameError('ILL DEFINED VARIABLES') return ufvalue
import numpy as np from uncertainties import ufloat from uncertainties import sqrt L = ufloat(32.351 * 10**(-3), 0 ) C = ufloat(0.851 * 10**(-9), 0) Csp = ufloat(0.037 * 10**(-9), 0) fp = 1 / (2 * np.pi * sqrt(L * C)) print("fp ohne Csp:") print(fp) Ck = ufloat(9.99 * 10**(-9),(9.99 * 10**(-9)) * 0.03) fp = 1 / (2 * np.pi * sqrt(L * (C + Csp))) fn = 1 / (2 * np.pi * sqrt((L/((1/C)+(2/Ck)) + L * Csp)) #print("fp:") #print(fp) #print("fn:") #print(fn) #nth = (fn + fp) / (2 * (fn - fp)) #print("nth:") #print(nth) #nexp = 12 #abw = (nexp/nth * 100) - 100 #print("abw:") #print(abw) Ck = ufloat(8.00 * 10**(-9),(8.00 * 10**(-9)) * 0.03) #fp = 1 / (2 * np.pi * sqrt(L * (C + Csp))) #fn = 1 / (2 * np.pi * sqrt((L/((1/C)+(2/Ck)) + L * Csp)) #print("fp:")