def calc_uncertainty(self): list_tmp = [] for i in self.data['list_dtx']: list_tmp.append(i * 0.001 / 15) # num_ua_d = sqrt( (Method.variance(self.data['list_d'])) / (10 * 9) ) num_ua_d = Method.a_uncertainty(list_tmp) # print(num_ua_d) num_ub1_d = 0.005 / sqrt(3) num_ub2_d = 0.1 / sqrt(3) num_u_d = sqrt(num_ua_d**2 + num_ub1_d**2 + num_ub2_d**2) self.data.update({ "num_ua_d": num_ua_d, "num_ub1_d": num_ub1_d, "num_ub2_d": num_ub2_d, "num_u_d": num_u_d }) num_d = self.data['num_d'] num_lbd = self.data['num_lbd'] num_c = self.data['num_c'] num_f = self.data['num_f'] num_u_f = self.data['num_u_f'] num_u_lbd = 2 * num_u_d num_u_c_c = sqrt((num_u_lbd / num_lbd)**2 + (num_u_f / num_f)**2) num_u_c = num_u_c_c * num_c self.data['num_u_c'] = num_u_c self.data['num_u_c_c'] = num_u_c_c self.data.update({"num_u_lbd": num_u_lbd}) num_u_lbd_1bit, pwr = Method.scientific_notation(num_u_lbd) num_u_f_1bit, pwr = Method.scientific_notation( num_u_f) # 将不确定度转化为只有一位有效数字的科学计数法 num_u_c_1bit, pwr = Method.scientific_notation( num_u_c) # 将不确定度转化为只有一位有效数字的科学计数法 num_fin_lbd = int(num_lbd * (10**pwr)) / (10**pwr) # 对物理量保留有效数字,截断处理 num_fin_f = int(num_f * (10**pwr)) / (10**pwr) num_fin_c = int(num_c * (10**pwr)) / (10**pwr) self.data['num_fin_c'] = "%.2f±%.2f" % (num_fin_c, num_u_c_1bit) self.data['num_fin_f'] = "%.0f±%.0f" % (num_fin_f, num_u_f_1bit) self.data['num_fin_lbd'] = "%.0f±%.0f" % (num_fin_lbd, num_u_lbd_1bit)
def calc_uncertainty(self): # 计算光程差d的a,b及总不确定度 ua_d = Method.a_uncertainty(self.data['d_arr']) # 这里容易写错,一定要用原始数据的数组 ub_d = 0.00005 / sqrt(3) u_d = sqrt(ua_d**2 + ub_d**2) self.data.update({"ua_d": ua_d, "ub_d": ub_d, "u_d": u_d}) # 计算圈数N的不确定度 N = self.data['N'] u_N = 1 / sqrt(3) self.data['u_N'] = u_N d, N = self.data['d'], self.data['N'] # 波长的不确定度合成 u_lbd_lbd = sqrt((u_d / d)**2 + (u_N / N)**2) lbd = self.data['lbd'] u_lbd = u_lbd_lbd * lbd self.data.update({"u_lbd_lbd": u_lbd_lbd, "u_lbd": u_lbd}) # 输出带不确定度的最终结果 # TODO: 输出最终结果的修约方法稍稍有点问题,待修改 bse, pwr = Method.scientific_notation(u_lbd) lbd_f = int(lbd * (10**pwr)) / (10**pwr) # 保留有效数字,截断处理 self.data['final'] = "%.0f±%.0f" % (lbd_f, bse)
def calc_data(self): # 实验一 # TODO ua_rx和ub_rx的计算方式有点问题 (不知道那个k是个什么物理量啊) num_b, num_a, num_r = Fitting.linear(self.data['list_x'], self.data['list_y'], False) self.data['num_a'] = num_a self.data['num_b'] = num_b self.data['num_r'] = num_r num_rx = num_b list_k = [] for i in range(0, 8): list_k.append(self.data['list_x'][i] / self.data['list_y'][i]) # num_ua_b = Method.a_uncertainty(list_k) num_k = 8 num_ave_x = Method.average(self.data['list_x']) num_ave_y = Method.average(self.data['list_y']) num_ua_b = num_b * (1 / (num_k - 2) * ((1 / num_r)**2 - 1))**(1 / 2) num_u_u = 0.00433 num_u_i = 0.0000433 num_ub_rx_rx = sqrt((num_u_u / num_ave_y)**2 + (num_u_i / num_ave_x)**2) num_ub_rx = num_ub_rx_rx * num_rx num_u_rx = (num_ub_rx**2 + num_ua_b**2)**(1 / 2) num_u_rx_1bit, pwr = Method.scientific_notation(num_u_rx) num_fin_rx = int(num_rx * (10**pwr)) / (10**pwr) self.data['num_ave_y'] = num_ave_y self.data['num_ave_x'] = num_ave_x self.data['num_ub_rx'] = num_ub_rx self.data['num_ub_rx_rx'] = num_ub_rx_rx self.data['num_u_u'] = num_u_u self.data['num_u_i'] = num_u_i self.data['num_rx'] = num_rx self.data['num_ua_b'] = num_ua_b self.data['num_u_rx'] = num_u_rx self.data['str_fin_rx'] = "%.0f±%.0f" % (num_fin_rx, num_u_rx_1bit) # 实验二 num_2r1 = self.data['list_2'][0] num_2u = self.data['list_2'][1] num_2r0 = self.data['list_2'][2] num_2d = self.data['list_2'][3] num_2r2 = self.data['list_2'][4] num_2rg = num_2r2 num_2ki = (num_2r1 * num_2u) / ((num_2r0 + num_2r1) * num_2rg * num_2d) num_dt_2r0 = InstrumentError.resistance_box(self.data['list_a0'], self.data['list_r0'], self.data['list_rbox0'][0]) num_dt_2r1 = InstrumentError.resistance_box(self.data['list_a1'], self.data['list_r1'], self.data['list_rbox0'][1]) num_dt_2r2 = InstrumentError.resistance_box(self.data['list_a2'], self.data['list_r2'], self.data['list_rbox0'][2]) num_u_2r0 = num_dt_2r0 / sqrt(3) num_u_2r1 = num_dt_2r1 / sqrt(3) num_u_2r2 = num_dt_2r2 / sqrt(3) num_u_2u = 0.005 * 3 / sqrt(3) num_u_2d = 1 / sqrt(3) num_u_2r1_2r0 = sqrt((num_u_2r1)**2 + (num_u_2r0)**2) num_u_2ki_2ki = sqrt((num_u_2r1 / num_2r1)**2 + (num_u_2r1_2r0 / (num_2r0 + num_2r1))**2 + (num_u_2u / num_2u)**2 + (num_u_2r2 / num_2r2)**2 + (num_u_2d / num_2d)**2) num_u_2ki = num_u_2ki_2ki * num_2ki num_u_2rg_1bit, pwr = Method.scientific_notation(num_u_2r2) num_fin_rg = int(num_rx * (10**pwr)) / (10**pwr) num_u_2ki_1bit, pwr = Method.scientific_notation(num_u_2ki) num_fin_ki = int(num_rx * (10**pwr)) / (10**pwr) self.data['str_fin_ki'] = "%.3f±%.3f" % (num_fin_ki, num_u_2ki_1bit) self.data['str_fin_rg'] = "%.0f±%.0f" % (num_fin_rg, num_u_2rg_1bit) self.data['num_dt_2r0'] = num_dt_2r0 self.data['num_dt_2r1'] = num_dt_2r1 self.data['num_dt_2r2'] = num_dt_2r2 self.data['num_2r1'] = num_2r1 self.data['num_2r2'] = num_2r2 self.data['num_2r0'] = num_2r0 self.data['num_2d'] = num_2d self.data['num_2u'] = num_2u self.data['num_u_2u'] = num_u_2u self.data['num_u_2d'] = num_u_2d self.data['num_u_2r1_2r0'] = num_u_2r1_2r0 self.data['num_u_2ki_2ki'] = num_u_2ki_2ki self.data['num_u_2ki'] = num_u_2ki self.data['num_2ki'] = num_2ki # 实验三 num_3rs = self.data['list_3'][0] num_3v = self.data['list_3'][1] num_3d = self.data['list_3'][2] num_3rg = self.data['list_3'][3] num_3ki = self.data['list_3'][4] num_u3_Nm1 = self.data['list_3'][7] num_u3_Nm2 = self.data['list_3'][8] num_u3_d = self.data['list_3'][9] num_u3_a1 = self.data['list_3'][5] num_u3_a2 = self.data['list_3'][6] num_u3_rg = self.data['list_3'][10] num_u3_ki = self.data['list_3'][11] num_3rxh = num_3rs / ((num_3rg + num_3rs) * num_3ki) * num_3v / num_3d num_u3_rs = InstrumentError.electromagnetic_instrument( num_u3_a1, num_u3_Nm1) / sqrt(3) num_u3_v = InstrumentError.electromagnetic_instrument( num_u3_a2, num_u3_Nm2) / sqrt(3) num_u3_r = (num_u3_rg**2 + num_u3_rs**2)**(1 / 2) num_u3_rxh_rxh = ((num_u3_rs / num_3rs)**2 + (num_u3_r / num_3rs)**2 + (num_u3_v / num_3v)**2 + (num_u3_ki / num_3ki)**2 + (num_u3_d / num_3d)**2)**(1 / 2) num_u3_rxh = num_u3_rxh_rxh * num_3rxh num_u3_rxh_1bit, pwr = Method.scientific_notation(num_u3_rxh) num_fin_rxh = int(num_3rxh * (10**pwr)) / (10**pwr) self.data['str_fin_rxh'] = "%.3f±%.3f" % (num_fin_rxh, num_u3_rxh_1bit) self.data['num_3rxh'] = num_3rxh self.data['num_u3_rs'] = num_u3_rs self.data['num_u3_v'] = num_u3_v self.data['num_u3_r'] = num_u3_r self.data['num_u3_rxh_rxh'] = num_u3_rxh_rxh self.data['num_u3_rxh'] = num_u3_rxh self.data['num_3rs'] = num_3rs self.data['num_3v'] = num_3v self.data['num_3d'] = num_3d self.data['num_3rg'] = num_3rg self.data['num_3ki'] = num_3ki self.data['num_u3_Nm1'] = num_u3_Nm1 self.data['num_u3_Nm2'] = num_u3_Nm2 self.data['num_2ki'] = num_2ki self.data['num_u3_d'] = num_u3_d self.data['num_u3_a1'] = num_u3_a1 self.data['num_u3_a2'] = num_u3_a2 self.data['num_u3_rg'] = num_u3_rg self.data['num_u3_ki'] = num_u3_ki