将一条线拟合到2分,而python中的错误

发布于 2025-01-28 06:48:19 字数 510 浏览 1 评论 0原文

我试图将一条线适应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。这显然是错误的,因为我可以从字面上进行错误传播,并通过手动进行计算来在ab上获取错误。有人可以帮助我解决此问题并获取参数错误吗?谢谢你!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文