Problem:
Hello, I am not extremely versed in numpy, so I am not exactly sure what I am doing wrong. I got it to work with made-up data but I am not sure as to what it is not working with the data I put in. All I am trying to do is fit the data I have, with the function. I am getting a result but I am not sure as to why I cannot plot the result.
x1 = [0 ,2 ,4 ,6 ,8 ,10 ,12 ,14 ,16 ,18 ,20 ,22 ,24 ,26 ,28 ,30 ,32 ,34 ,36 ,38 ,40 ,42 ,44 ,46]
x = np.array(x1)
y1data = [82.3 ,78.5 ,74.3 ,70.7 ,67.6 ,65 ,62.5 ,60.1 ,58.1 ,56.1 ,54.3 ,52.8 ,51.2 ,49.9 ,48.6 ,47.2 ,46.1 ,45 ,43.9 ,43 ,41.9 ,41 ,40.1 ,39.5]
y1 = np.array(y1data)
y2data = [68.8 ,64.8 ,62.1 ,59.9 ,57.7 ,55.9 ,53.9 ,52.3 ,50.8 ,49.5 ,48.1 ,46.8 ,45.9 ,44.8 ,43.7 ,42.6 ,41.7 ,40.8 ,39.9 ,39.3 ,38.6 ,37.7 ,37 ,36.4]
y2 = np.array(y2data)
def func(t, T, r, Ts):
return (T - Ts) * np.exp(-r * t) + Ts
xdata = x1
y1data = y1
y2data = y2
popt, pcov = curve_fit(func, xdata, y1data)
plt.plot(xdata, y1data, 'b-', label='black coffee')
plt.plot(xdata, func(xdata, *popt), 'r-',
label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt))
plt.xlabel('t')
plt.ylabel('T')
plt.legend()
plt.show()
The error I am getting is following below
TypeError: 'numpy.float64' object cannot be interpreted as an integer