cftool and fit function returns different results

2 次查看(过去 30 天)
I fit data using both methods and am getting different results.
The fitted function is: f(x)=a*x^(b).
The results are:
cftool: a=3.238e+10, b=-1.573.
fit function: a=1.516e+07, b=-1.111.
And of course, the goodness of fit parameters are different.
I set the options in the fit function to be the same as in cftool.
The script:
PowerEqn='a*x^(b)';
fo = fitoptions('Method','NonlinearLeastSquares',...
'Robust','off',...
'Algorithm','Trust-Region',...
'DiffMinChange',1e-8,...
'DiffMaxChange',.1,...
'MaxFunEvals',600,...
'MaxIter',400,...
'TolFun',1e-6,...
'TolX',1e-6,...
'StartPoint',[x(1),y(1)]);
ft=fittype(PowerEqn,'options',fo);
[f,stat]=fit(x',y',ft);
The Data:
x=[1.5804e+07,1.1580e+08,2.1580e+08,3.1580e+08,4.1580e+08,5.1580e+08,6.1580e+08,7.1580e+08,
8.1580e+08,9.1580e+08,1.0158e+09,1.1158e+09,1.2158e+09,1.3158e+09,1.4158e+09];
y=[1.5398e-01,4.7623e-03,6.6259e-03,1.7019e-03,1.4101e-03,0,5.8168e-06,
0,0,0,0,0,0,0,0]
  3 个评论
yonatan s
yonatan s 2018-9-27
编辑:yonatan s 2018-9-27
yeah you're right. but in cftool I pressed on FitOptions button (see image) and just entered those results. so what am I missing?
dpb
dpb 2018-9-27
编辑:dpb 2018-9-27
Your starting points aren't the same as in the cftool window -- if I use the builtin form of the equation I get the default result.
However using the text form for the equation and the [x(1) y(1)] startpoints then I get your same result. So, there's something going on behind the scenes...
>> fit(x',y','power1',fo)
ans =
General model Power1:
ans(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 3.231e+10 (-6.071e+10, 1.253e+11)
b = -1.573 (-1.746, -1.399)
>> fo.StartPoint=[x(1) y(1)];
>> fit(x',y','power1',fo)
ans =
General model Power1:
ans(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 3.276e+10 (-6.174e+10, 1.273e+11)
b = -1.574 (-1.748, -1.4)
>> eqn='a*x^b';
>> fit(x',y',eqn,fo)
ans =
General model:
ans(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 1.58e+07 (-2.917e+07, 6.077e+07)
b = -1.114 (-1.285, -0.9424)
>> fo.StartPoint=[8.2638E11 -1.7388];
>> fit(x',y',eqn,fo)
ans =
General model:
ans(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 8.264e+11 (-3.335e+12, 4.988e+12)
b = -1.768 (-2.072, -1.464)
>>
What, specifically, I've no klew

请先登录,再进行评论。

回答(0 个)

类别

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