I have a system which can be modelled by coupled differential equations:
Therefore, variables are: S, R and unknown parameters are: kt, ka, kd and Rmax.
I need to find the unknown parameters and simulate a curve that will fit my data. I have measured R as a function of time experimentally, which is the only data I have. I know the value of A. How do I carry out numerical integration and use nonlinear least squares curve fitting on my data?
Here is something I tried, but the calculation goes on for hours until I have to abort it manually.
function S = NumInt(U, t)
% dS/dt = kt * (A - S)- ka * S * (Rmax - R)+ kd * R; % dR/dt = (ka * S * (Rmax - R) - kd * R; % Variables: y(1) = S, y(2) = R; % Parameters: kt = U(1), ka = U(2), kd = U(3), Rmax = U(4)
y0 = rand(2,1);
[T,Y] = ode45(@Int, t, y0); function dy = Int(t, y) dy = zeros(2,1); dy(1) = U(1) * (A - y(1)) - U(2) * y(1) * (U(4)- y(2) + U(3) * y(2)); dy(2) = U(2) * y(1) * (U(4) - y(2)) - U(3) * y(2);
U0 = rand(4,1) * 10; [U] = lsqcurvefit(@NumInt, U0, t, y, , );
No products are associated with this question.
Since you are trying to fit a curve to an ODE, this page in the documentation has good pointers on the best solver to choose and how to go about it:
Your function NumInt returns a solution structure S. Your lsqcurvefit call takes (xdata,ydata) arguments as t and y. Did you do some internal conversions to ensure that the correct data is passed between your functions?
Also, I hope you realize that the previous comment about using norm((ydata-y)^2) is incorrect. The note in the lsqcurvefit function reference page explains this very important point.
MATLAB mathematical toolbox documentation