将一条线拟合到2分,而python中的错误
我试图将一条线适应2点,这些点在y轴上有错误,但我似乎无法从中弄清楚不确定性。这是我的(非常简单的)代码:
import numpy as np
from scipy.optimize import curve_fit
nu = np.array([0,1])
B = np.array([0.191989,0.19089])
err_B = np.array([5,50])*1e-5
def lin(x, a, b):
return a-b*(x+1/2)
popt, pcov = curve_fit(lin, nu, B,sigma=err_B)
print(popt)
print(np.sqrt(np.diag(pcov)))
对于实际值,我得到了我的期望,但是对于错误,我会得到inf
。这显然是错误的,因为我可以从字面上进行错误传播,并通过手动进行计算来在a
和b
上获取错误。有人可以帮助我解决此问题并获取参数错误吗?谢谢你!
I am trying to just fit a line to 2 points that have errors on the y axis but I can't seem to get the uncertainty out of it. Here is my (very simple) code:
import numpy as np
from scipy.optimize import curve_fit
nu = np.array([0,1])
B = np.array([0.191989,0.19089])
err_B = np.array([5,50])*1e-5
def lin(x, a, b):
return a-b*(x+1/2)
popt, pcov = curve_fit(lin, nu, B,sigma=err_B)
print(popt)
print(np.sqrt(np.diag(pcov)))
For the actual values I get what I expect, but for the errors I get inf
. This is clearly wrong, as I can literally do error propagation and get the error on a
and b
by doing the calculations by hand. Can someone help me fix this issue and get the errors on the parameters? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论