I took the example of the official documantation page of scipy optimize curve_fit.(https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html) and modified the function in the example a little bit and scipy throws a warning "Covariance of the parameters could not be estimated" and gives me a bad fit. In my opion the fit of such a not really special function should be work fine, so that curve_fit seem to be working badly or I am missing some points and had a bad start? Could someone give me a hint what is the problem or which libary I could use instead.
from scipy.optimize import curve_fit
def func(x, a, b, c):
return a - b*np.exp(-c*x)
xdata = np.linspace(0, 4, 50)
y = func(xdata, 823.5, 5.3, 8.2)
rng = np.random.default_rng()
y_noise = 0.2 * rng.normal(size=xdata.size)
ydata = y + y_noise
plt.plot(xdata, ydata, 'b-', label='data')
popt, pcov = curve_fit(func, xdata, ydata)
plt.plot(xdata, func(xdata, *popt), 'r-', label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt))
plt.plot(xdata, y, 'g--', label='Original')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.show()```