I have some trouble to fit a set of value with the given function : f(x)= const*(1-(x/a)**b)**c
I am using python 3.6.3 with the following code :
import numpy as np
import scipy.optimize as opt
from scipy.optimize import curve_fit
x=[0.,0.4,0.8,1.6,2.,2.4]
y=[0.09882902,0.07298427,0.05111438,0.01679405,0.00517385,0.00065633]
def func(x,a,b,c):
return y[0] * ( 1 - (x/a)**b )**c
x0=np.array([2.0,0.9,1.5])
opt.curve_fit(func,x,y,p0=x0)
I have the following error message:
RuntimeWarning: invalid value encountered in power
return y[0] * ( 1 - (x/a)**b )**c
///: OptimizeWarning: Covariance of the parameters could not be estimated
category=OptimizeWarning)
The problem seems to appear because of the last exponent, because the following function will work fine :
def func(x,a,b,c):
return y[0] * ( 1 - (x/a)**b )*c