我无法为我的代码解密错误消息以找到适合两个参数(eps 和 sig)的复杂最小二乘的一些参数。
from pylab import *
import scipy
import numpy as np
from scipy import integrate, optimize
# Estimate parameters with least squares fit
T = [90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300]
B = [-0.2221, -0.18276, -0.15348, -0.13088, -0.11293, -0.09836, -0.086301, -0.076166, -0.067535, -0.060101, -0.053636, -0.047963, -0.04295, -0.038488, -0.034494, -0.030899, -0.027648, -0.02469, -0.022, -0.019534, -0.017268, -0.015181]
def funeval(Temp,eps,sig):
return -2.*np.pi*scipy.integrate.quad( lambda x: np.exp(4.*eps/Temp*((sig/x)**6.-(sig/x)**12.)*(x**2)) ,0.0,Inf )[0]
def residuals(p,y,Temp):
eps,sig = p
err = y-(funeval(Temp,eps,sig) )
return err
print funeval(90.,0.001, 0.0002)
plsq = scipy.optimize.leastsq(residuals, [0.00001, 0.0002], args=(B, T))
funeval
给出了一个合理的浮点数,但是当我运行它返回的代码时:
error: Supplied function does not return a valid float.
该错误似乎对初始条件不敏感。我是 python 新手,所以任何帮助或帮助指南将不胜感激。谢谢。