Why is it that if I adjust a curve with the curve fitting tool, it does not give me the same results as if I fit it without the tool?

조회 수: 2 (최근 30일)
Hello, community,
I am trying to fit a series of points with a power function with and without the tool, using the same starting points and having different results. Maybe it is an obvious question but I would like to know why. Here are the two codes and the data attached:
function y = myfunction(x,a1,b1)
y=a1*x.^b1;
end
ft5 = fittype( 'myfunction(x,a1,c1)' )
f5 = fit( x_inter',y_inter', ft5,'StartPoint', [8.64593401687141e-71 16.7561500073752] )
plot( f5, x_inter, y_inter )
With the following results:
General model:
f5(x) = myfunction(x,a1,c1)
Coefficients (with 95% confidence bounds):
a1 = 3.368e-71 (-1.784e-70, 2.458e-70)
c1 = 16.76 (16.13, 17.38)
An this is the code generated by the tool:
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( x_inter, y_inter );
% Set up fittype and options.
ft = fittype( 'power1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [8.64593401687141e-71 16.7561500073752];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData, 'predobs', 0.99 );
legend( h, 'y_inter vs. x_inter', 'untitled fit 1', 'Lower bounds (untitled fit 1)', 'Upper bounds (untitled fit 1)', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'x_inter', 'Interpreter', 'none' );
ylabel( 'y_inter', 'Interpreter', 'none' );
grid on
Getting the results:
General model Power1:
f(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 9.531e-154 (-3.249e-153, 5.155e-153)
b = 35.54 (35.1, 35.97)
Goodness of fit:
SSE: 1.796e+07
R-square: 0.9771
Adjusted R-square: 0.9771
RMSE: 94.82
Thank you!

채택된 답변

Matt J
Matt J 2021년 12월 11일
편집: Matt J 2021년 12월 11일
In the first case, fit() doesn't know anything about the structure of your curve model. The details are hidden inside myfunction().
In the second case, you are specifying one of the Toolbox's stock library of curve models. It therefore knows more about the curve and uses a different method to estimate the parameters, one that is specifically tailored to power1.
Because a different solution method is used, a different path is taken by the iterative solver, and a different solution can be reached, when the solution is non-unique. Here, when a=0 (as was the case in both versions), the solution for the b parameter is indeed non-unique.
  댓글 수: 2
Angelavtc
Angelavtc 2021년 12월 11일
편집: Angelavtc 2021년 12월 11일
Thanks @Matt J is there any way to call the curve fitting tool by regions? This is linked to my last question (https://fr.mathworks.com/matlabcentral/answers/1608110-how-can-i-find-where-to-split-a-piecewise-regression-and-find-the-parameters-involved-in-the-functio?s_tid=srchtitle= ). What I mean is, can I call the linear fitting tool when X is less than 23000 and the power fit when x is above 23000? I see that the curve fitting tool adjusts better to any curve. Thank you!
Matt J
Matt J 2021년 12월 11일
If you can extract a subset of data in that region, you can just fit it in the normal way.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by