我想要评估的功能是
d y / d ln(x)
其中d是导数。但是我有一组x和y的数据点,有不确定性。现在我认为可以通过查找日志空间中数据的斜率来评估这种导数,但是我不确定这个分析公式是否正确转换为离散公式。
下面的加权最小二乘函数是正确的,我想知道上面公式的评估是否与代码中的斜率值A相对应?如果没有,我将如何评估它?
import numpy as np
x = 0.5*np.array([
2900 + 3700,3700 + 3950,3950 + 4113,4113 + 4250,
4250 + 4400,4400 + 4500,4500 + 4600,4600 + 4700,
4700 + 4800,4800 + 4900,4900 + 5000,5000 + 5100,
5100 + 5200,5200 + 5300 ])
y = np.array([
0.14429,0.14408,0.14467,0.14500,
0.14653,0.14491,0.14396,0.14376,
0.14447,0.14461,0.14381,0.14301,
0.14361,0.14541])
yerr = np.array([
0.00230, 0.00143, 0.00089, 0.00088,
0.00087, 0.00093, 0.00085, 0.00073,
0.00086, 0.00076, 0.00081, 0.00081,
0.00089, 0.00077])
def wleastsq(x,y,w):
# weighted least squares
# y = Ax + B
d = sum(w)*sum(w*x*x) - sum(x*w)**2
B = (sum(w*x*x)*sum(w*y) - sum(w*x)*sum(w*x*y))/d
A = (sum(w)*sum(w*x*y) - sum(w*x)*sum(w*y))/d
# uncertainties
sigA = np.sqrt( sum(w*x*x)/d )
sigB = np.sqrt( sum(w)/d )
return A,B,[sigA,sigB]
A,B,sig = wleastsq( np.log(x),y,1./yerr )