Numerical integration with nonlinear least squares curve fitting?
Mostrar comentarios más antiguos
I have a system which can be modelled by coupled differential equations:
- dS/dt = kt * (A - S) - ka * S * (Rmax - R)+ kd * R;
- dR/dt = ka * S * (Rmax - R) - kd * R;
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.
1st m-file:
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);
A= 50;
[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);
end
end
2nd m-file:
U0 = rand(4,1) * 10;
[U] = lsqcurvefit(@NumInt, U0, t, y, [], []);
Respuestas (2)
Shashank Prasanna
el 15 de En. de 2013
0 votos
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:
4 comentarios
Shashank Prasanna
el 15 de En. de 2013
Since the optimization just minimizes the objective function, make sure that you write your objective function such that it finds the sum of squared errors of the difference between the data and the fitted model for each iteration
norm((ydata-y)^2)
TP
el 16 de En. de 2013
Shashank Prasanna
el 16 de En. de 2013
I haven't seen you entire code, but this link should help you:
TP
el 17 de En. de 2013
Alan Weiss
el 17 de En. de 2013
0 votos
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.
Alan Weiss
MATLAB mathematical toolbox documentation
2 comentarios
TP
el 17 de En. de 2013
Alan Weiss
el 21 de En. de 2013
[T,Y] = ode15s(@Int,xvalues,[0 0]);
Instead of having NumInt return S, it should return [T,Y]:
function [T,Y] = NumInt(U,t);
This outputs the times T and values Y of the calculated solution points of the ODE.
Use these values, which I suppose become the xdata and ydata for lsqcurvefit, and you should be able to continue.
You might also want to set DiffMinChange to a higher value than default, perhaps 1e-4, as suggested here.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!