Curve fitting to data using fit
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Editor
el 11 de Oct. de 2022
Comentada: Alex Sha
el 10 de Dic. de 2024
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])
plot(fittedmdl,'k.')
hold on
plot(t,x,'.m', MarkerSize=20)
And I obtain the following figure:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1152158/image.jpeg)
I am not impressed with the fitting. Can someone please check where I could be going wrong. Thanks in anticipation.
9 comentarios
Cris LaPierre
el 11 de Oct. de 2022
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1152378/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1152383/image.png)
Respuesta aceptada
Matt J
el 11 de Oct. de 2022
Editada: Matt J
el 11 de Oct. de 2022
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])
H=plot(fittedmdl,t,x);
H(1).MarkerSize=20; H(1).Color='m';
H(2).Color='k';H(2).LineWidth=2;
2 comentarios
Alex Sha
el 10 de Dic. de 2024
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!