I'm trying to fit the data in this file with
thefile = open("aluminio_33920um_aire.txt", "r")
data = np.loadtxt(thefile, delimiter='\t', skiprows=1)
Temp = data[:, 0] + 273.15 #kelvin
Time = data[:, 1]*1e-3 #secs
def newton(t, a, b, tau):
return a + b * np.exp(-t/tau)
def dulong(t, ta, dift, f, n):
return ta + (dift + (n-1)*t/f)**(1/(1-n))
poptd, pcovd = curve_fit(dulong, Time, Temp, p0=[295, 0.155, 6000, 1.38], sigma=*len(Temp), absolute_sigma=True)
RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 1000.
Your dulong function is highly sensitive to changes in n because of its
n^n dependancy. You might want set bounds for it or even keep it as a constant if thats good enough for you.
Also, if you are dealing with sufficient small timescales you could consider using a approximating function. If not, try to take the logarithm of your temp data and fit the logarithm of the dulong function. This can be useful if the algorithm takes steps too big when variating n.
For debugging purposes you can add a line to your function which prints the parameters passed, that way you will be able to see which parameter is varied by how much and you can work from there. As another measure you can take a look at the minimize function from scipy.optimize, there you will be able to specify more options like solving algorithm and stepwidth to be taken and you can also pass the jacobian to further improve efficiency.