Nonlinear fit of segmented curve
조회 수: 5 (최근 30일)
이전 댓글 표시
How would I go about getting a nonlinear least-squares fit of a segmented curve? In this case, I have a short, linear, lag period followed by a logistic growth phase (typical of bacterial growth in culture).
Thus, for x < T0, y = Y0; for x >= T0, y = Y0 + (Plateau-Y0)*(1 - exp(-K*(X-X0)).
I need least squares estimates for each of the parameters: T0, Y0, Plateau, and K
I've attempted to use a custom function in the curve fitting toolbox, but cannot figure out how to allow for the two curves.
Thanks!
댓글 수: 0
채택된 답변
Teja Muppirala
2012년 12월 5일
It is no problem to fit piecewise curves in MATLAB using the Curve Fitting Toolbox. You can deal with piecewise functions by multiplying each piece by its respective domain. For example:
rng(0); %Just fixing the random number generator for initial conditions
X = (0:0.01:10)';
% True Values
Y0_true = 3;
PLATEAU_true = 5;
K_true = 1;
X0_true = 4;
Y = [Y0_true] * (X <= X0_true) + [Y0_true + (PLATEAU_true-Y0_true)*(1 - exp(-K_true*(X-X0_true)))].* (X > X0_true);
Y = Y + 0.1*randn(size(Y));
plot(X,Y);
ftobj = fittype('[Y0] * (x <= X0) + [Y0 + (PLATEAU-Y0)*(1 - exp(-K*(x-X0)))].* (x > X0)');
cfobj = fit(X,Y,ftobj,'startpoint',rand(4,1))
hold on;
plot(X,cfobj(X),'r','linewidth',2);
댓글 수: 5
Jonathan Gößwein
2022년 10월 14일
The problem are the startpoints, rand(4,1) does not work indeed, but with an appropriate selection the method works (e.g. the true values).
추가 답변 (2개)
John Petersen
2012년 12월 4일
Not sure how you would do that, but you could try using a sigmoid function which will get you close, relatively speaking. Something like, for example,
y2 = Y0 + (Plateau-Y0)./(1 + exp(-K*(X-X0)));
laoya
2013년 5월 14일
Hi Teja Muppirala,
I am also interested in this topic. Now my problem is: if the express of curves are not expressed explicitly, but should be calculated by functions, how to use this function?
Thanks, Tang Laoya
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!