Fit an exponential curve

조회 수: 3 (최근 30일)
Sahar khalili
Sahar khalili 2021년 7월 7일
댓글: Star Strider 2021년 7월 8일
Hi, I have a data set like this
x=[6.5 2.45 2.7 1.85 2.25 1.35 1.4 1 0.7 .475 .66 .475];
y=[0.40 0.80 1 1.40 1.80 2.50 3.00 4.00 6.00 7.00 8.00 9.00];
and I want to fit an exponential curve like this: y=6.5*e^(-a*x) to my data set. Since, the value 6.5 is constant I do not get my desired reslut from cftool. Does anybody know how can I solve this?

채택된 답변

Star Strider
Star Strider 2021년 7월 7일
Try this —
x=[6.5 2.45 2.7 1.85 2.25 1.35 1.4 1 0.7 .475 .66 .475];
y=[0.40 0.80 1 1.40 1.80 2.50 3.00 4.00 6.00 7.00 8.00 9.00];
[fitobject,gof,output] = fit(x(:),y(:),'6.5*exp(-a*x)')
Warning: Start point not provided, choosing random start point.
fitobject =
General model: fitobject(x) = 6.5*exp(-a*x) Coefficients (with 95% confidence bounds): a = 0.4585 (0.1848, 0.7323)
gof = struct with fields:
sse: 35.1246 rsquare: 0.6496 dfe: 11 adjrsquare: 0.6496 rmse: 1.7869
output = struct with fields:
numobs: 12 numparam: 1 residuals: [12×1 double] Jacobian: [12×1 double] exitflag: 3 firstorderopt: 0.0109 iterations: 7 funcCount: 16 cgiterations: 0 algorithm: 'trust-region-reflective' stepsize: 2.6832e-04 message: 'Success, but fitting stopped because change in residuals less than tolerance (TolFun).'
figure
plot(fitobject, x, y, 'p')
grid
.
  댓글 수: 2
Sahar khalili
Sahar khalili 2021년 7월 8일
Thank you so much. Yes, it works.
Star Strider
Star Strider 2021년 7월 8일
As always, my pleasure!
.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 7월 7일
1st of all, your data's good fit is not 6.5*exp(a*x) that is why cftool is giving you the best fit that differs from your expected 6.5*exp(-a*x).
If you're aiming to get a fit for 6.5*exp(-a*x) then use "custom equation" option and set it to 6.5*exp(-a*x).

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by