Talk:FAQ/@comment-4472617-20110923152244

hello everyone： there is a matlab curve fitting program： clc clear xx = 1:1:20; xx = xx'; yy = exp(xx); hold on; plot(xx,yy,'o'); start = [1 1 1]; s = fitoptions('Method','NonlinearLeastSquares',...            'Lower',[-Inf,-Inf,-Inf],...             'Upper',[Inf,Inf,Inf],...             'Startpoint',start); f = fittype('a*x^b+c','options',s); [coe,gof] = fit(xx,yy,f); coe gof plot(coe,'r'); grid on;

the fitting result is not satisfied：

General model: coe(x) = a*x^b+c Coefficients (with 95% confidence bounds): a =      2.035  (-6885, 6889) b =      4.595  (-1139, 1148) c =      1.006  (-8.515e+07, 8.515e+07) gof = sse: 2.6959e+17 rsquare: -0.1105 dfe: 17 adjrsquare: -0.2411 rmse: 1.2593e+08 then I use the curve fitting tool in matlab toolbox, the result is fine:

General model Power2: f(x) = a*x^b+c Coefficients (with 95% confidence bounds): a =    5.2e-17  (1.568e-17, 8.832e-17) b =      19.19  (18.96, 19.43) c =          0  (-6.271e+05, 6.271e+05)

Goodness of fit: SSE: 2.398e+13 R-square: 0.9999 Adjusted R-square: 0.9999 RMSE: 1.188e+06 I guss the problem is the startpoint set, because when I set the startpoint as [5.2e-17 19.19 0], my program can get a fine result too. here are the source code generated by matlab tool box：

% --- Create fit "fit 3" ok_ = isfinite(xx) & isfinite(yy); if ~all( ok_ ) warning( 'GenerateMFile:IgnoringNansAndInfs',...       'Ignoring NaNs and Infs in data.' ); end st_ = [222.34950513063478184 4.0772761680206128787 28384745.637977682054 ]; ft_ = fittype('power2');

% Fit this model using new data cf_ = fit(xx(ok_),yy(ok_),ft_,'Startpoint',st_); when I put the upper 'startpoint' into my source code, the result is not the same as the tool box. I would like to know the answers of the two questions: 1. I use the same startpoint as in the toolbox, but the results are different, why? At the same time the ''startpoint' in toolbox are of great different with the final value of a, b, c, where the problem comes from, and how to resolve it ? 2.The source code generated in matlab tool box doesn't have the way of getting 'startpoint' value, I would like to know haw the 'startpoint' value came from, and what can I do to get the 'startopint' value via programing ? Waiting for your reply, thank you !