fitting data with exponential + linear form

3 ビュー (過去 30 日間)
찬 소
찬 소 2020 年 8 月 20 日
回答済み: Md Shariful Islam 2023 年 6 月 22 日
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.

回答 (2 件)

Alan Stevens
Alan Stevens 2020 年 8 月 20 日
編集済み: Alan Stevens 2020 年 8 月 20 日
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 件のコメント
찬 소
찬 소 2020 年 8 月 21 日
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 2020 年 8 月 21 日
編集済み: Alan Stevens 2020 年 8 月 21 日
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.

サインインしてコメントする。


Md Shariful Islam
Md Shariful Islam 2023 年 6 月 22 日
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')
"

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by