0

我刚开始使用在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
4

1 回答 1

0

不确定性只能是一个实数。因此,当您使用 更改标称值时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
于 2015-07-28T18:20:31.860 回答