试图拟合简化的Bloch-Grüneisen曲线以提高灵敏度。不是Python最好的,所以有点混乱。
这一切似乎都可以“优化”,直到得到curve_fit的错误消息为止:
IndexError:只有整数,切片(
:
),省略号(...
),numpy.newaxis(None
)和整数或布尔数组都是有效索引
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as sc
from scipy.optimize import curve_fit
import scipy.constants as spc
import scipy as spy
Cu_2000A=np.genfromtxt('Cu_2000A.txt')
R = Cu_2000A[:,0]
T = Cu_2000A[:,1]
ylist = []
def Bloch1(T,k,debye):
for Tval in np.nditer(T):
yval = float((k*(Tval/debye)**5))
ylist.append(yval)
return ylist
xlist = []
def Integrate(debye):
for Tval in np.nditer(T):
xval =(sc.quad(lambda x: ((x**5)/(((np.exp(x))-1)*(1-(np.exp(-x))))), 0, (debye/(Tval))))
xlist.append(float(xval[0]))
return xlist
def Bloch(T, R0, k, debye):
test = np.asarray(Bloch1(T, k, debye))
test2 = np.asarray(Integrate(debye))
return (R0 + (test*test2))
popt, pcov = curve_fit(Bloch, T, R [0.1, 1000, 350])