0

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.

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
  • 1
    Would you please add just enough example data to reproduce the problem? – James Phillips Jan 06 '20 at 21:35
  • The data contains for each time_s and temperature round about 13000 points. Time_s [0, 60, 120, 180, 240, ...] and temperature_mean [15.49, 15.60, 15.65, ...]. The temperature as a somewhat exponetial growth. For lam_guess i take 2 as start value, for Rb_guess 0.1. Does this help? And thx for the reply. – BagpipeWayne Jan 06 '20 at 21:52
  • 1
    The code you have posted will not run, it has no import statements for example. Please edit in the import statements and all data so that I do not have to figure that out and edit the code for you - it makes helping you much easier if you post complete example code that both runs and reproduces the problem. – James Phillips Jan 07 '20 at 00:20
  • Sorry for answering that late. I´m in the field right now and will provide the whole code when im back – BagpipeWayne Jan 09 '20 at 16:49

0 Answers0