remake
This commit is contained in:
commit
25d76fd510
16
main.py
Normal file
16
main.py
Normal file
@ -0,0 +1,16 @@
|
||||
from uncertainly import Uncertainly
|
||||
import logger
|
||||
|
||||
number_input: str = input("Data input:")
|
||||
type_B_uncertain: float = float(input("type_B_uncertain: "))
|
||||
param_tp: float = float(input("tp input: "))
|
||||
|
||||
number_list:tuple = number_input.split
|
||||
|
||||
try:
|
||||
numbers = [float(num_str) for num_str in number_list]
|
||||
uncertain_processor = Uncertainly(numbersm, type_B_uncertain=type_B_uncertain,param_tp=param_tp)
|
||||
uncertain_processor.output_std
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
27
uncertainly.py
Normal file
27
uncertainly.py
Normal file
@ -0,0 +1,27 @@
|
||||
class Uncertainly:
|
||||
__slots__ = [
|
||||
"average"
|
||||
]
|
||||
|
||||
def __init__(self, data: tuple, type_B_uncertain: float, param_tp: float):
|
||||
self.average:float = sum(data) / len(data)
|
||||
self.length = len(data)
|
||||
|
||||
# def cal_standard_deviation(self):
|
||||
data_cut = [datum-self.average for datum in self.input_data]
|
||||
|
||||
self.standard_deviation:float = sum(data_cut) / self.length
|
||||
|
||||
self.type_A_uncertain:float = param_tp * self.standard_deviation / sqrt(self.length)
|
||||
|
||||
self.total_uncertain = 2 * sqrt(self.type_A_uncertain**2 + type_B_uncertain**2)
|
||||
self.type_B_uncertain = type_B_uncertain
|
||||
|
||||
def output_std(self):
|
||||
print(f"平均为:{data}/{self.length}={self.average}\n")
|
||||
# print(f"{self.average}\n")
|
||||
print(f"标准差:{self.standard_deviation}")
|
||||
print(f"3S区间:[{self.average - 3 * self.standard_deviation},{self.average +3 * self.standard_deviation}]")
|
||||
print(f"B类不确定度确认:{self.type_B_uncertain}\n")
|
||||
print(f"总不确定度:2 * ✓{self.type_A_uncertain}^2 + {self.type_B_uncertain}^2={self.total_uncertain}")
|
||||
print(f"结果表达式为:{self.average}+-{self.total_uncertain}")
|
Loading…
x
Reference in New Issue
Block a user