Reputation: 460
In attempting to fit an exponential to data, scipy.optimize.curve_fit returns a TypeError
x = np.array([0.,1200.02220551,3600.06661654,6000.11102756,8400.15543858,10800.19984961])
y = np.array([0.51057636,0.63187347,0.72030091,0.75168574,0.79036657,0.81551974])
def f(x,p1,p2):
p1*np.exp(x*p2)
popt, pcov = curve_fit(f, x, y)
Unfortunately this returns the following error:
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
Any suggestions of what has gone wrong here would be greatly appreciated.
Upvotes: 0
Views: 856
Reputation: 23647
f
needs to return its result.
def f(x,p1,p2):
return p1*np.exp(x*p2)
Note: Don't be surprised if you get a different error (optimal parameters not found). The data looks logarithmic rather than exponential. Switching x and y (curve_fit(f, y, x)
) might work with an exponential function.
Upvotes: 1