Electronic – Formula to Predict Delta Temperature based on previous trend

heattemperature

I need a way to predict delta temperature curve based on previous trend. I do a lot of heat rise testing on electrical conductors and I would like to be able to atleast get an approximation of the curve before it is done.

For example if I already have the data points in this curve before the line. I want to me able to predict the rest after the line. It doesn't have to be that accurate. If I am within 10% that would be fine.

enter image description here


ETA:
I'd like to ahead some more light on this question. I think part of the problem with exponential decay not fitting to my graph is that the ambient rose over time. See below I added ambient to my graph and created another that is only rise over ambient. Disregard the large dip in rise over ambient after it stabilized. This data comes from a test that was done outside, so wind and or sun/shade could account for that.

Sample and Ambient Temperatures
enter image description here
Rise over Ambient
enter image description here

Best Answer

As Majenko said, curve fitting using Least Squares is an appropriate solution. However, you must pick an appropriate function to fit to. A direct line fit is not appropriate here for long time predictions, but is good enough for short time predictions.

A more appropriate function is an exponential decay function: \begin{align*} T = a - b e^{-c t} \end{align*}

This is a non-linear function and thus requires some sort of iterative process to get the fitting parameters a, b, and c. However, it's not too hard to do. The basic idea is to use a Newton-Raphson root finding algorithm along with a least squares algorithm. Luckily, there are several pre-existing implementations. If you're interested in learning the mathematical derivation, see here (though it does get quite technical).

Here is an implementation using Scipy's leastsq function. I use an explicit Jacobian matrix because for some reason the estimated Jacobian gives bonkers results.

import numpy as np
from scipy.optimize import leastsq
def exp_decay(args, t):
    '''
    args: list-like with the 3 curve fitting parameters a,b,c
    t: times
    '''
    a,b,c = args
    return a - b*np.exp(-c*t)

def jac(args, T, t):
    a,b,c=args
    res = np.zeros([3,len(t)])
    res[0,:] = -1
    res[1,:] = np.exp(-c*t)
    res[2,:] = -b*t*np.exp(-c*t)
    return res

def find_coeffs(T, t):
    '''
    helper for finding the fitting coefficients
    '''
    resid = lambda args,T,t: T-exp_decay(args, t)
    return leastsq(resid, np.array([1,1,1e-9]), args=(T,t), Dfun=jac, col_deriv=True)[0]

# some dummy data to demonstrate usage
T = np.array([-5,0,5,7,9,12.5,15,17])
t = np.array([1,500,935,1402,1869,2803,3737,4600])

coeffs = find_coeffs(T,t)

# plot the results to show the fit
t_p = np.linspace(1,25000,25000)
from matplotlib.pyplot import *
plot(t_p, exp_decay(coeffs, t_p), label='exponential decay fit')
plot(t,T,'o')
grid(True)
show()

To demonstrate why using an appropriate function matters, I pulled a few rough data points from your plot (marked in green in the plot) and fit both a line and the exponential decay function to them. As you can see, a line fit gets the answer roughly right for a very short period of time, but deviates a lot over longer times. The exponential decay fit is much closer, and adding more data points would give a better final answer.

enter image description here

Related Topic