Reputation: 51
I'm given the following equation and asked to find a few different things one of which is the least squares estimate.
I have the experimentally determined data and write the function.
xData = np.array([0, 2, 5, 10, 15, 20, 25, 30]) # hours
yData = np.array([ 0.398, 0.543, 1.56, 4.34, 7.22, 9.86 , 10.5, 10.6]) # biomass, g/L
def func1(t,x_infin,x_0,k):
'nonlinear function in a and b to fit to data'
g = x_infin/ (1+(((x_infin-x_0)/x_0)*math.exp(-k*t)))
return g
I then set up curve_fit()
initial_guess = [10.5,0.0,16.5] # intial guesses for x_infin, x_0 and k
pars, pcov = curve_fit(func1, xData, yData, p0 = initial_guess)
and get
only size-1 arrays can be converted to Python scalars
I'm not sure where I am passing an array where it shouldn't be. My understanding of the curve_fit() from the documentation is that I'm passing in the function, xdata ydata and then my guesses for the parameters.
Could someone point out where i'm going wrong?
Upvotes: 3
Views: 789