如何通过在python中估计电池的参数来减少模拟数据和实验数据之间的误差

2024-06-02 07:05:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我想减少模型模拟数据和实验室实验数据之间的误差。正如我在这篇文章中提出的解决方案:enter link description here

但是,我尝试了scipy.optimize.curve_fit,没有得到想要的结果。 我在应用优化之前得到的结果: enter image description here

我尝试的代码:

from scipy.optimize import curve_fit

Vocv = Data.loc[:,'Vocv']
Tt=    Data.loc[:, 'Tt']                       
It=    Data.loc[:, 'It'] 
X = np.array([Vocv, It, Tt])

def voltage_1(X, a0, a1, a2, a3):    
    return (X[0]+(a0*X[1])+(a1*X[1])*(1-np.exp(-1/(a1*a3))*X[2]))
g = [2.448e-07, 3e-07, 0.2, 0.2]
g = np.asarray(g)
n2 = len(t)
y2_1 = []


for i in range(n2):
    temp = voltage_1((Vocv[i],It[i],Tt[i]), g[0], g[1], g[2], g[3])
    if temp is not None:
        y2_1.append(temp)

y2_1 = np.asarray(y2_1)

hr2 = Experimental_Voltage

a, cov = curve_fit(voltage_1, X, hr2, p0=g, method='lm') 
print(a)    

y2 = np.empty(n2)
    
for i in range(n2):
    y2[i] = voltage_1((Vocv[i], It[i], Tt[i]), a[0], a[1], a[2], a[3])

font = {'size'   : 15}
import matplotlib
matplotlib.rc('font',**font)
t2 = Experimental_Time
fig = plt.figure()
plt.plot(t,y2, c='r', marker = 'o')
plt.plot(t2,hr2, c='k', marker = '>')
plt.legend(loc = 'best')

优化后得到的结果如下:

enter image description here

预期结果是:enter image description here

我现在陷入了困境。任何帮助都将不胜感激。我可以亲自发送的数据样本


Tags: 数据dataa1npitplttemploc