Curve fitting to data using fit
Show older comments
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:

I am not impressed with the fitting. Can someone please check where I could be going wrong. Thanks in anticipation.
9 Comments
Ghazwan
on 11 Oct 2022
Is there a fit quality you are looking for?
Editor
on 11 Oct 2022
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))
Ghazwan
on 11 Oct 2022
ok. It looks like this is higher order fitting model.
Matt J
on 11 Oct 2022
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
on 11 Oct 2022
John D'Errico
on 11 Oct 2022
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
on 11 Oct 2022
Cris LaPierre
on 11 Oct 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)
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



