与标称值对应的可变不确定性
variable uncertainty corresponding to nominal value
我刚开始使用在 http://pythonhosted.org/uncertainties/index.html#
找到的 uncertainties
模块
假设我们有一个带有校准温度传感器的实验装置。现在考虑校准产生了可变的测量误差,例如从 ± 1 K @ 0 °C 线性增加到 ± 4 K @ 100 °C。是否可以定义自定义函数,以便在使用 uncertainties
模块定义变量时使用?
示例:
>>> from uncertainties import ufloat
>>> def err_fun(temp_in_C):
..: return 1 + 3 / 100 * temp_in_C
>>> temp_meas = ufloat(10, err_fun, 'tag')
>>> print temp_meas
10+/-1.3
如果是这样,当变量的标称值改变时,变量的不确定性是否改变?
示例:
>>> print temp_meas
10+/-1.3
>>> temp_meas.nominal_value = 50
>>> print temp_meas
50+/-2.5
不确定性只能是实数。因此,当您使用 temp_meas.nominal_value = 50
更改标称值时,您只会更改标称值(而不是不确定性)。
针对您的情况,最简单的解决方案可能是动态创建具有不确定性的温度:
def temp_with_uncert(temp_in_C):
return ufloat(temp_in_C, 1 + 0.03 * temp_in_C)
给出:
>>> temp_with_uncert(10)
10.0+/-1.3
>>> temp_with_uncert(50)
50.0+/-2.5
我刚开始使用在 http://pythonhosted.org/uncertainties/index.html#
找到的uncertainties
模块
假设我们有一个带有校准温度传感器的实验装置。现在考虑校准产生了可变的测量误差,例如从 ± 1 K @ 0 °C 线性增加到 ± 4 K @ 100 °C。是否可以定义自定义函数,以便在使用 uncertainties
模块定义变量时使用?
示例:
>>> from uncertainties import ufloat
>>> def err_fun(temp_in_C):
..: return 1 + 3 / 100 * temp_in_C
>>> temp_meas = ufloat(10, err_fun, 'tag')
>>> print temp_meas
10+/-1.3
如果是这样,当变量的标称值改变时,变量的不确定性是否改变?
示例:
>>> print temp_meas
10+/-1.3
>>> temp_meas.nominal_value = 50
>>> print temp_meas
50+/-2.5
不确定性只能是实数。因此,当您使用 temp_meas.nominal_value = 50
更改标称值时,您只会更改标称值(而不是不确定性)。
针对您的情况,最简单的解决方案可能是动态创建具有不确定性的温度:
def temp_with_uncert(temp_in_C):
return ufloat(temp_in_C, 1 + 0.03 * temp_in_C)
给出:
>>> temp_with_uncert(10)
10.0+/-1.3
>>> temp_with_uncert(50)
50.0+/-2.5