这种场景下如何使用curve_fit?

问题描述 投票:0回答:1

好吧,我有两个数组 T 和 I0 数据。

我正在尝试将这些数据拟合到方程中以找到带隙,例如。这是我的代码:

T = np.array([ 93, 100, 110, 130, 140, 159, 179, 195, 210, 224, 241, 255, 265,283, 293])
I0 = np.array([3.89071815e-05, 3.86379100e-05, 3.19573788e-05, 2.75543444e-05,3.00226067e-05, 3.59134864e-05, 3.92161213e-05, 4.37321918e-05,4.59245870e-05, 4.95912369e-05, 5.24583115e-05, 5.47069424e-05,5.73620696e-05, 5.80254459e-05, 7.23664434e-05])

def fit_func(T, Eg):
   T3 = T**3
   arg = -Eg/(kB * T)
   I0 = c*T3*np.exp(arg)
return I0 
params, cov = curve_fit(fit_func, T, I0, p0= 4.239e-19)

但这似乎不起作用。 params 给我的值与最初的猜测完全相同,并且 cov 是 inf。我不知道出了什么问题。请帮忙。

python numpy curve-fitting
1个回答
0
投票

如果您的数据正确(但我会检查它),那么该函数似乎最适合 Eg

值。

下面的代码包含

c
以及
Eg
作为要查找的参数。我假设
kB
是玻尔兹曼常数。

最合适的似乎是

Eg, c =  -5.4109181863198085e-21 7.211320673443582e-13

但我真的不相信你的数据。

import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import numpy as np

kB = 1.380649e-23

T = np.array([ 93, 100, 110, 130, 140, 159, 179, 195, 210, 224, 241, 255, 265,283, 293])
I0 = np.array([3.89071815e-05, 3.86379100e-05, 3.19573788e-05, 2.75543444e-05,3.00226067e-05, 3.59134864e-05, 3.92161213e-05, 4.37321918e-05,4.59245870e-05, 4.95912369e-05, 5.24583115e-05, 5.47069424e-05,5.73620696e-05, 5.80254459e-05, 7.23664434e-05])

def fit_func( T, Eg, c ):                                                                                            
   return c * T ** 3 * np.exp( -Eg / ( kB * T ) )

Eg = -1.0e-20         # initial guess
c = 1.0e-10

params, cov = curve_fit( fit_func, T, I0, p0=[ Eg, c ] )
Eg, c = params
print( "Eg, c = ", Eg, c )

fit = c * T ** 3 * np.exp( -Eg / ( kB * T ) )

plt.plot( T, I0, label="data" )
plt.plot( T, fit, label="curve fit" )
plt.legend()
plt.show()

© www.soinside.com 2019 - 2024. All rights reserved.