我试图以y = A(1-exp(-t/tau))+A0的形式拟合一个简单模型,但curve_fit会产生错误
Covariance of the parameters could not be estimated
我的默认参数不够健壮吗?下面是我的代码和数据:第一个
8fq7wneg1#
您需要为参数(p0)提供合适的初始猜测值。下面的代码和图像拟合模型:
p0
import numpy as np from matplotlib import pyplot as plt from scipy.optimize import curve_fit time = [0, 30, 45, 60, 75, 90, 300, 600] des2 = [19.042, 19.019, 19.018, 19.012, 19.011, 19.009, 18.990, 18.984] def first_order(t, A, tau, A0): t0 = t[0] y = - (A * (1 - np.exp(-(t - t0) / tau)) + A0) return y parameters, _ = curve_fit(first_order, time, des2, p0=(1, 100, 1)) plt.plot(time, des2) plt.plot( np.linspace(time[0], time[-1], 100), first_order(np.linspace(time[0], time[-1], 100), *parameters), "--", ) plt.show()
1条答案
按热度按时间8fq7wneg1#
您需要为参数(
p0
)提供合适的初始猜测值。下面的代码和图像拟合模型: