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

Can you show us the fit that was generated? Show us the display of the variable u in the Command Window.
John D'Errico
John D'Errico on 13 Nov 2020
Edited: John D'Errico on 13 Nov 2020
More useful yet would be to provide the data itself, attach a .mat file that has only your data in it. I know of two very good reasons why the fit did not work, but it is easier to explain with your data.
for sure; follow the data
Are you extracting out parts of that data? What you show on the plot is quite deceptive compare to the full data.
It looks like you might have extracted from index 2655 to 2739 (might be off by 1 on the endpoint)
sigh.
Follow what data?
By the way: there are duplicate points in the second column (the one you appear to be using as x), even if you restrict to the point range I indicated.
Here, one of that relaxation time. Sorry about last data.
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.
Ok I'll try, but I used 'exp2' to simulate a circuit, where the parameter of a fit, equals 1/RC, bring to me a value of R and C. Can I also do this with polynomial fit?

Sign in to comment.

 Accepted Answer

You can solve this problem turning all de values of X axis to zero.

More Answers (1)

John D'Errico
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:

1 Comment

Thanks, sorry waste your time. I learned a lott of your coment, really helps. Thanks again.

Sign in to comment.

Categories

Products

Release

R2018a

Community Treasure Hunt

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

Start Hunting!