gpt4 book ai didi

python - curve_fit 不能正常使用 4 个参数

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:44 25 4
gpt4 key购买 nike

运行下面的代码,

x = np.array([50.849937, 53.849937, 56.849937, 59.849937, 62.849937, 65.849937, 68.849937, 71.849937, 74.849937, 77.849937, 80.849937, 83.849937, 86.849937, 89.849937, 92.849937])
y = np.array([410.67800, 402.63800, 402.63800, 386.55800, 330.27600, 217.71400, 72.98990, 16.70860, 8.66833, 40.82920, 241.83400, 386.55800, 394.59800, 394.59800, 402.63800])
def f(om, a, i , c):
return a - i*np.exp(- c* (om-74.)**2)
par, cov = curve_fit(f, x, y)
stdev = np.sqrt(np.diag(cov) )

产生这个图表,

enter image description here

具有以下参数和标准差:

par =   [ 4.09652163e+02, 4.33961227e+02, 1.58719772e-02]
stdev = [ 1.46309578e+01, 2.44878171e+01, 2.40474753e-03]

但是,当尝试将此数据拟合到以下函数时:

def f(om, a, i , c, omo):
return a - i*np.exp(- c* (om-omo)**2)

它不起作用,它产生的标准偏差为

stdev = [inf, inf, inf, inf, inf]

有什么办法可以解决这个问题吗?

最佳答案

看起来它没有收敛(参见 thisthis )。尝试添加一个初始条件,

par, cov = curve_fit(f, x, y, p0=[1.,1.,1.,74.])

结果是

par = [ 4.11892318e+02, 4.36953868e+02, 1.55741131e-02, 7.32560690e+01])
stdev = [ 1.17579445e+01, 1.94401006e+01, 1.86709423e-03, 2.62952690e-01]

关于python - curve_fit 不能正常使用 4 个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39716026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com