111
This commit is contained in:
parent
365412aff4
commit
e6e555dcac
BIN
src/__pycache__/uncertainly.cpython-38.pyc
Normal file
BIN
src/__pycache__/uncertainly.cpython-38.pyc
Normal file
Binary file not shown.
1
src/log.py
Normal file
1
src/log.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
import logger
|
16
src/main.py
Normal file
16
src/main.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from uncertainly import Uncertainly
|
||||||
|
|
||||||
|
number_input = 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]
|
||||||
|
print(numbers)
|
||||||
|
uncertain_processor = Uncertainly(data=numbers, type_B_uncertain=type_B_uncertain,param_tp=param_tp)
|
||||||
|
uncertain_processor.output_std()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
36
src/uncertainly.py
Normal file
36
src/uncertainly.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
from math import sqrt
|
||||||
|
|
||||||
|
class Uncertainly:
|
||||||
|
__slots__ = [
|
||||||
|
"average",
|
||||||
|
"length",
|
||||||
|
"standard_deviation",
|
||||||
|
"type_A_uncertain",
|
||||||
|
"type_B_uncertain",
|
||||||
|
"total_uncertain",
|
||||||
|
"data"
|
||||||
|
]
|
||||||
|
|
||||||
|
def __init__(self, data: tuple, type_B_uncertain: float, param_tp: float):
|
||||||
|
self.data = data
|
||||||
|
self.average:float = sum(self.data) / len(self.data)
|
||||||
|
self.length = len(self.data)
|
||||||
|
|
||||||
|
# def cal_standard_deviation(self):
|
||||||
|
data_cut = [(datum-self.average) ** 2 for datum in self.data]
|
||||||
|
|
||||||
|
self.standard_deviation:float = sqrt(sum(data_cut) / (self.length - 1))
|
||||||
|
|
||||||
|
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"平均为:{self.data}/{self.length}={self.average}\n")
|
||||||
|
# print(f"{self.average}\n")
|
||||||
|
print(f"标准差:{round(self.standard_deviation,4)}")
|
||||||
|
print(f"3S区间:[{round(self.average - 3 * self.standard_deviation,4)},{round(self.average +3 * self.standard_deviation,4)}]")
|
||||||
|
print(f"B类不确定度确认:{self.type_B_uncertain}\n")
|
||||||
|
print(f"总不确定度:2 * ✓{round(self.type_A_uncertain,4)}^2 + {round(self.type_B_uncertain,4)}^2={round(self.total_uncertain,4)}")
|
||||||
|
print(f"结果表达式为:{round(self.average,4)}+-{round(self.total_uncertain,4)}")
|
Loading…
x
Reference in New Issue
Block a user