I am trying to fit a kinetic model for population growth and decay of four variables A,B,C,D in a chemical system. I am trying to solve the following set of equations, which I have attached in matrix form:
where t is a time step and k1,k2,k3 are constants in an exponential function. I want to fit curves based on these equations to solve for k1,k2, and k3 given my populations of A,B,C,D.
For this I am using optimize.curve_fit, t is the time step in a (1000,) array, X is a (4,1000) matrix and where u and w are the two matrices:
from scipy import optimize
def func(t,X,k1,k2,k3):
u = np.array([[1,0,0],
[-k1/(k1+k2-k3),k1/(k1+k2-k3),0],
[(k1*k3)/((k1+k2-k3)*(k1+k2)),-k1/(k1+k2k3),k1/(k1+k2)],
[-k2/(k1+k2),0,k2/(k2+k1)]],dtype=float)
w = np.array([[np.exp(-t*(k1+k2))],
[np.exp(-t*k3)],
[1]])
return X*np.dot(u,w)
X = np.array([A,B,C,D]) # A,B,C,D are (1000,) arrays
# X.shape = (4, 1000)
# t.shape = (1000,)
optimize.curve_fit(func,t,X,method='lm')
When I run this piece of code, I get the following output:
ValueError: object too deep for desired array
error: Result from function call is not a proper array of floats.
I have seen in a similar post that the shapes of the arrays in important, but as far as I can tell these are correct.
Could anyone suggest where the problem may be in this code and how I can best go about solving for k1,k2,k3 using the curve fit function?
Thanks

funcdoes not needXparameter, yourtis the x param. Also, the 3rd element in matrixwis of length one, it should be of length 1,000 to match the other 2 elements aboveXis a bad name for a variable here ; I should call it ``Y, so that my x param istand my y param isY, whereYis the matrix of shape (4,1000). For the third element of matrixw, I just want it to be a constant, so that when the dot product is taken with matrix u, the third column inuis returned as a constant.func(t,X,k1,k2,k3).curve_fittreats all parameters after the first as parameters to be fit. So it tries to fitX,k1,k2, andk3.