A类不准确度的脚本编写

最近一直在做实验,算A类不准确度烦的一比,于是写了个脚本。顺便复习一下Numpy库

流程图:
在这里插入图片描述
完整代码:

import numpy as np


# 判断次数获取t/sqrt(n)的值
def judge_tims(x):
	if x == 2:
		return 8.99
	elif x == 3:
		return 2.48
	elif x == 4:
		return 1.59
	elif x == 5:
		return 1.24
	elif x == 6:
		return 1.05
	elif x == 7:
		return 0.93
	elif x == 8:
		return 0.84
	elif x == 9:
		return 0.77
	elif x == 10:
		return 0.72


# 计算s的值
def countS(ts, x):
	a_mean = np.ones(ts)
	print("平均值为:", np.mean(x))
	a_mean[:] = np.mean(x)
	x1 = np.square(x - a_mean)
	return np.sqrt(np.ndarray.sum(x1) / (ts - 1))


# 主函数
if __name__ == '__main__':
	times = int(input("请输入计算的次数"))
	c = 1
	nums = list()
	while c <= times:
		nums.append(float(input("请输入第" + str(c) + "次的值:")))
		c = c + 1
	S = countS(times, nums)
	T = judge_tims(times)
	result=S*T
	print("A类不确定度为:", result)

本脚本不具有修约功能,还得你自己修约!!!

猜你喜欢

转载自blog.csdn.net/weixin_52387684/article/details/121247557