I have data x sampled at times t. I would like to fit my function to this data. Below is a code.
clear; close all
x=[100; 85.4019292604501; 77.9310344827586; 79.3365583966828; 70.3524533;
13.213644524237; 24.5654917953199; 12.6526340272125;
9.71822886716503; 9.99113213124446; 10.525];
t=[0; 24; 24; 24; 24; 48; 48; 48; 72; 72; 72;];
mdl=fittype('A*exp((-C.*(1-exp(-lambda.*t))/lambda)-(D*(exp(-lambda.*t)-1+lambda.*t)/lambda^2))','indep','t');
fittedmdl = fit(t,x,mdl,'start',[0.1 0.1 0.1 0.1])
fittedmdl =
General model: fittedmdl(t) = A*exp((-C.*(1-exp(-lambda.*t))/lambda)-(D*(exp(-lambda.*t) -1+lambda.*t)/lambda^2)) Coefficients (with 95% confidence bounds): A = 100 (84.3, 115.7) C = -120.9 (-9.45e+09, 9.45e+09) D = 6.135 (-4.793e+08, 4.793e+08) lambda = 105.9 (-8.273e+09, 8.273e+09)
plot(fittedmdl,'k.')
hold on
plot(t,x,'.m', MarkerSize=20)
And I obtain the following figure:
I am not impressed with the fitting. Can someone please check where I could be going wrong. Thanks in anticipation.

댓글 수: 9

Ghazwan
Ghazwan 2022년 10월 11일
Is there a fit quality you are looking for?
Editor
Editor 2022년 10월 11일
@Ghazwan Yes. I want it to be in the form as the figure below
That is not a lot a data points to fit a rather complex equation to. Can you confirm that the equation as coded is correct?
syms A C D lambda t
A*exp((-C.*(1-exp(-lambda.*t))/lambda)-(D*(exp(-lambda.*t)-1+lambda.*t)/lambda^2))
ans = 
Ghazwan
Ghazwan 2022년 10월 11일
ok. It looks like this is higher order fitting model.
Matt J
Matt J 2022년 10월 11일
Your starting guess [0.1 0.1 0.1 0.1] looks very arbitrary. Surely you do not expect lambda to have a similar value to the other parameters like A.
Editor
Editor 2022년 10월 11일
The coefficient 'C' shoulb be negative. It should be
John D'Errico
John D'Errico 2022년 10월 11일
You CANNOT fit a higher order model to this data. If you do, expect garbage. Why? You have only 4 data points, even though some of them are replicates. So no more than 4 parameters can be estimated. At least if you want them to make any sense. And even at that, expect poor results.
As far as getting poor results, you need to provide good starting values for exponential models. Provide crappy or random starting values, then expect crappy/random results. I don't have time right now to look seriously at your data to decide if the model can fit that data, or what are good starting values. I'll look back in later today though.
Editor
Editor 2022년 10월 11일
Thank you all for your constructive comments. I can tell that one of the problem could be the poor choice of initial conditions for this complex model. I will try though to play around with the initial condtions to see whether anything good can come out.
Thank you once again
Cris LaPierre
Cris LaPierre 2022년 10월 11일
Just responding about the missing negative sign. The negative sign before C has been applied to the contents inside parentheses. So it is there.
-C(1-exp(t)) is the same as C(exp(t)-1)

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2022년 10월 11일
편집: Matt J 2022년 10월 11일

0 개 추천

x=[100; 85.4019292604501; 77.9310344827586; 79.3365583966828; 70.3524533;
13.213644524237; 24.5654917953199; 12.6526340272125;
9.71822886716503; 9.99113213124446; 10.525];
t=[0; 24; 24; 24; 24; 48; 48; 48; 72; 72; 72;];
mdl=fittype('A*exp((-C.*(1-exp(-lambda.*t))/lambda)-(D*(exp(-lambda.*t)-1+lambda.*t)/lambda^2))','indep','t');
fittedmdl = fit(t,x,mdl,'start',[100 0.1 0.1 0.1],'Lower',[0 0 0 0])
fittedmdl =
General model: fittedmdl(t) = A*exp((-C.*(1-exp(-lambda.*t))/lambda)-(D*(exp(-lambda.*t) -1+lambda.*t)/lambda^2)) Coefficients (with 95% confidence bounds): A = 108.1 (88.32, 128) C = 4.114e-14 (fixed at bound) D = 0.001322 (0.0002522, 0.002393) lambda = 8.823e-07 (-0.0381, 0.0381)
H=plot(fittedmdl,t,x);
H(1).MarkerSize=20; H(1).Color='m';
H(2).Color='k';H(2).LineWidth=2;

댓글 수: 2

Editor
Editor 2022년 10월 11일
Thank you @Matt J for your help
If only for @Editor's 11 sets of data, the result from Matt J's code is a local solution, the best one should be:
Sum Squared Error (SSE): 222.486707072606
Root of Mean Square Error (RMSE): 4.49733968911932
Correlation Coef. (R): 0.991854679874119
R-Square: 0.983775705988192
Parameter Best Estimate
--------- -------------
a 100.656116307162
c 0.00236233265266791
d 0.00102171687180199
lambda 2.87765446399321E-10
The SSE from Matt J's is about 614.5217, much bigger than above which is 222.4867

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

질문:

2022년 10월 11일

댓글:

2024년 12월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by