Vladimir Vargas - 2 months ago 19
Python Question

# Curve_fitting data (I'm close to the params values, but curve_fit says optimal parameters not found)

I'm trying to fit the data in this file with

`curve_fit`
from scipy in Python. The file contains data points of temperature vs time in celsius and milliseconds. I convert them to kelvin and seconds:

``````thefile = open("aluminio_33920um_aire.txt", "r")
Temp = data[:, 0] + 273.15  #kelvin
Time = data[:, 1]*1e-3  #secs
thefile.close()
``````

I define a couple of functions to be fitted:

``````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))
``````

newton's fitting works perfectly. But dulong does not. I have plotted several values for the parameters of duolong to see which values draw a line that more or less fits the data, and I found the values given here:

``````poptd, pcovd = curve_fit(dulong, Time, Temp, p0=[295, 0.155, 6000, 1.38], sigma=[1]*len(Temp), absolute_sigma=True)
``````

However, passing these values
`p0`
to curve_fit does not help since I get the error

``````RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 1000.
``````

Don't know how to improve since the initial guess of my parameters is a really good guess. I appreciate your help.

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.