Fit with exp2 doesn't working
13 views (last 30 days)
Show older comments
Mauro Cesar Ribeiro Junior
on 13 Nov 2020
Answered: Mauro Cesar Ribeiro Junior
on 25 Nov 2020
Hi, I'm a student trying to use fit 'exp2' on a matlab data. My documents have amount of steps, discharges of a battery where a looping separate them in semicircles and applay the fit at every semi circle. But the answer of fit is a line. Bellow I show at the image. The spots are the data and the line is fit. How can I solve this? I try using another data but the same happens. Ty for your attention.
9 Comments
Walter Roberson
on 17 Nov 2020
Those trailing downslopes make a big difference.
For that data you might as well use a polynomial of degree 2 with centering and scaling and LAR robust fitness. Visually it doesn't look like a great fit, but is above 0.99 and it is difficult to do better than that without going to something like fourier with 9 terms.
Accepted Answer
More Answers (1)
John D'Errico
on 17 Nov 2020
Edited: John D'Errico
on 17 Nov 2020
I'll assume you want to fit this using a sum of two exponentials? Since that is the way you plotted it, I assume that is so.
That simply won't happen in this orientation. Not EVER.
Why not? First, an exponential does not have a point where the curve has an infinite slope. Exponentials lack singularities! And clearly this curve has a singularity around x == 8e4. Tryign to use exp2 to fit this data in this orientation is a waste of time. You will never find a good fitting model of that form.
Next, do you want to fit that part where it drops off at the top end? If not, then why did you include it in the data? Again, you won't be able to find a sum of exponentials model that will behave that way. So I'll crp that data, then flip the axes to have even a remote chance.
k = x < 9.27e4;
plot(y(k),x(k),'o')
At least in this form, the data looks vaguely exponential.
ft = fittype('a + exp(c*(x-b))','indep','x');
mdl = fit(y(k),x(k),ft,'start',[8,3.564,40])
mdl =
General model:
mdl(x) = a + exp(c*(x-b))
Coefficients (with 95% confidence bounds):
a = 7.964e+04 (7.95e+04, 7.978e+04)
b = 3.543 (3.541, 3.545)
c = 357.4 (331.8, 383.1)
plot(y(k),x(k),'o')
hold on
plot(mdl)
I say this over and over again. You NEED good starting values for exponential models. You NEED to understand what the parameters mean in those models, else you are wasting your time.
Is that a good model for the system? Clearly not, as it shows significant lack of fit.
Would the exp2 model form be more meaningful here? NO! You absolutely need a constant term in the model. And anyway, if this model is even close to reasonable, then it would imply a log style model as you wanted to fit the data.
Far better in any event is a spline model, but even there, you cannot fit a spline to data with a singularity in it. But using my SLM toolbox (free download from the File Exchange)
slm = slmengine(y(k),x(k),'knots',15,'plot','on','concaveup','on','increasing','on');
which is about as good as you could possibly expect on this data. Find SLM here:
See Also
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!