测量牛顿环的曲率半径实验数据处理代码

对于直接测量量的A类不确定度求解

total_1 = 0
total_2 = 0


def f(x=[], y=[]):
    global total_1, total_2
    total_1 = 0
    total_2 = 0
    for i in range(len(x)):
        total_1 += x[i]
    for i in range(len(y)):
        total_2 += y[i]

    return total_1 / len(x), total_2 / len(y)


def g(x=[], y=[]):
    mean_x, mean_y = f(x, y)
    sum_of_squares_x = 0
    sum_of_squares_y = 0
    for i in range(len(x)):
        deviation_x = x[i] - mean_x
        print(f"第{i + 1}个数据的均差为:{deviation_x}")
        sum_of_squares_x += deviation_x ** 2
    for i in range(len(y)):
        deviation_y = y[i] - mean_y
        print(f"第{i + 1}个数据的均差为:{deviation_y}")
        sum_of_squares_y += deviation_y ** 2

    print(f"列表 x 的均差平方和为: {sum_of_squares_x}")
    print(f"列表 y 的均差平方和为: {sum_of_squares_y}")

    # 计算A类不确定度
    n_x = len(x)
    n_y = len(y)
    if n_x > 1:
        u_a_x = (sum_of_squares_x / (n_x * (n_x - 1))) ** 0.5
        print(f"列表 x 的A类不确定度为: {u_a_x}")
    else:
        print("列表 x 数据量不足,无法计算A类不确定度。")

    if n_y > 1:
        u_a_y = (sum_of_squares_y / (n_y * (n_y - 1))) ** 0.5
        print(f"列表 y 的A类不确定度为: {u_a_y}")
    else:
        print("列表 y 数据量不足,无法计算A类不确定度。")


# 示例调用
x = [9.604, 9.601, 9.600, 9.604]
y = [0.821, 0.824, 0.819, 0.823]
result_1, result_2 = f(x, y)
print(f"列表 x 的元素均值为: {result_1}")
print(f"列表 y 的元素均值为: {result_2}")
g(x, y)
    

传递不确定度的计算


import math

def calculate_value_and_uncertainty(a, b, c, d, da, db, dc, dd):
    # 计算函数值
    value = (a * b) / (c * d)
    # 计算相对不确定度的平方和
    relative_uncertainty_squared = (da / a) ** 2 + (db / b) ** 2 + (dc / c) ** 2 + (dd / d) ** 2
    # 计算传递不确定度
    uncertainty = value * math.sqrt(relative_uncertainty_squared)
    return value, uncertainty



a = 9.602
b = 0.822
c = 589.3
d = 15
da = 0.097
db = 0.003
dc = 0.1
dd = 0.2


value, uncertainty = calculate_value_and_uncertainty(a, b, c, d, da, db, dc, dd)

print(f"函数值: {value}")
print(f"传递不确定度: {uncertainty}")
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值