对于我的硕士学位论文,我正在尝试实现一个代码,该代码评估时间和温度的测量数据,然后使用最小二乘法计算变量。问题是Python似乎并没有改变积分边界中的变量。如果有人熟悉,该模型基于用于热响应测试的移动线源。代码如下所示:
def model(time_s, coeffs):
integral = []
for t in time_s:
def f(u):
return np.exp(-((x0 ** 2 / ((coeffs[0] / cv) + alpha_l * vth))
+ (y0 ** 2 / ((coeffs[0] / cv) + alpha_t * vth)))
* (vth ** 2 / (16 * ((coeffs[0] / cv) + alpha_l) * vth * u)) - u) * (1 / u)
i, err = quad(f, 0, ((vth ** 2) * t / (4 * ((coeffs[0] / cv) + alpha_l * vth))))
integral.append(i)
integral = np.asarray(integral)
return (heatflow / (4 * m.pi * cv * np.sqrt(((coeffs[0] / cv) + alpha_l * vth) *
((coeffs[0] / cv) + alpha_t * vth)))) \
* np.exp((vth * x0) / (2 * ((coeffs[0] / cv) + alpha_t * vth))) * integral\
+ Tb + coeffs[1] * heatflow
def residuals(coeffs, y, time_s):
return y - model(time_s, coeffs)
guess = [lam_guess, Rb_guess]
x, flag = leastsq(residuals, guess, args=(time_s, temperature_mean))
因此,我需要为coeffs[0]
和coeffs[1]
获得良好的价值。问题在于Python仅更改coeffs[1]
的变量。
有没有更好的方法来实现在每个时间步长更改积分边界的模型?
我想我对四边形和/或最小二乘的工作方式有误。