fitting data with exponential + linear form

4 vues (au cours des 30 derniers jours)
찬 소
찬 소 le 20 Août 2020
I want to fit my data into
y= a*exp(-x/b)+cx+d (exponential linear form).
I got number of data set of about 600.
If I put it in
y= a*exp(-x)+cx+d, it works although it doesn't fit 'best'
explinearfit = fittype({'exp(-x)','x','1'})
fo = fitoptions(explinearfit);
fo.normalize = 'on';
myFit = fit(t2,n,explinearfit);
plot(myFit,t2,n)
xlabel('time(t2)')
ylabel('electrons(n)')
legend('Data','Fitted graph')
title('Data and Fitted Curve')
clear opts
However, if I put 'b' inside the exponential, it goes way wrong.
explinearfit = fittype('a*exp(-x/b)+c*x+d')
fo = fitoptions(explinearfit);
fo.normalize = 'on';
myFit = fit(t2,n,explinearfit);
plot(myFit,t2,n)
xlabel('time(t2)')
ylabel('electrons(n)')
legend('Data','Fitted graph')
title('Data and Fitted Curve')
clear opts
How can I fix this?
The warning sign says that there are no starting points so they were randomly chosen.

Réponses (2)

Alan Stevens
Alan Stevens le 20 Août 2020
Modifié(e) : Alan Stevens le 20 Août 2020
Try starting with the following guesses: a = 6E10, b = 4E-4, c = 0, d = -1.57E12.
with
explinearfit = fittype( @(a,b,c,d,x) a*exp(-x/b)+c*x+d );
(I'm guessing at the fittype as I don't have the Curve fitting toolbox myself!).
  4 commentaires
찬 소
찬 소 le 21 Août 2020
Yeap! I got the reasonable fit as well.
But how did you guess the initial values?
I think I might also have other sets of data.
Alan Stevens
Alan Stevens le 21 Août 2020
Modifié(e) : Alan Stevens le 21 Août 2020
First I looked at x = 0 and set a+d to a value near the top of the points. Then at the other end it looked as if the curve might be asymptotically horizontal, so, with x set at infinity, I set c = 0, and d to a value near the bottom of the points (thus allowing me to get a as well). I then just plotted the resulting curve against the points, starting with b = 1, and adjusted b until I got what looked like a reasonable fit by eye (it took about four guesses) . The constants were never going to be perfect, but were likely to provide a decent initial guess.

Connectez-vous pour commenter.


Md Shariful Islam
Md Shariful Islam le 22 Juin 2023
Hi,
In this code, do we just need to declare the initial guesses(a = 6E10, b = 4E-4, c = 0, d = -1.57E12) before following code?
I was trying to reproduce the plot with best fit as I encounter similar issues. However, I could not get a good fit rather I am getting a fit like 2nd image.
May I get a working code for this problem?
"
explinearfit = fittype('a*exp(-x/b)+c*x+d')
fo = fitoptions(explinearfit);
fo.normalize = 'on';
myFit = fit(t2,n,explinearfit);
plot(myFit,t2,n)
xlabel('time(t2)')
ylabel('electrons(n)')
legend('Data','Fitted graph')
title('Data and Fitted Curve')
"

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by