fitting data with exponential + linear form

조회 수: 8 (최근 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 CenterFile Exchange에서 Get 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