For my master's thesis I'm trying to implement a code that evaluates measured data of time and temperature and then calculates variables with the least-squares method. The problem is Python doesn't seem to change the variables in the integral boundary. The model is based on the moving line source for thermal response test, if anyone is familiar with that. The code is shown below:
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))
So I need to get a good value for coeffs[0]
and coeffs[1]
. The problem is that Python only changes the variable for coeffs[1]
.
Is there a better way to implement a model witch changing integral boundary for each time step taken?
I guess, I get something wrong about how quad and/or least-squares is working.