Numerical integration with nonlinear least squares curve fitting?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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, [], []);
0 Kommentare
Antworten (2)
Shashank Prasanna
am 15 Jan. 2013
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 Kommentare
Shashank Prasanna
am 16 Jan. 2013
I haven't seen you entire code, but this link should help you:
Alan Weiss
am 17 Jan. 2013
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 Kommentare
Alan Weiss
am 21 Jan. 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
Siehe auch
Kategorien
Mehr zu Matrix Computations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!