lsqcurvefit fitting not good

4 ビュー (過去 30 日間)
Zuyu An
Zuyu An 2019 年 10 月 17 日
編集済み: Alex Sha 2019 年 10 月 22 日
>> xdata = ...
[0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05 0.055 0.06 0.065 0.07 0.075 0.08];
ydata = ...
[-1.5641 4.331 10.226 10.328 10.43 9.2075 7.9845 6.9538 5.9227 4.7857 3.6488 2.1603 0.67176 0.22867 -0.21442 -0.10787];
fun = @(x,xdata)x(1)+x(2).*sqrt(x(3)./((2.*pi.*x(4).*(xdata+x(5))).^3)).*exp(-x(3).*((x(4).*(xdata+x(5))-x(6)).^3)./(2.*x(4).*(xdata+x(5)).*x(6).^2));
x0 = [0,8,0.9,13,0.01,0.9];
x = lsqcurvefitlsqcurvefit(fun,x0,xdata,ydata)
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt');
lb = [];
ub = [];
times = linspace(xdata(1),xdata(end));
plot(xdata,ydata,'ko',times,fun(x,times),'b-')
legend('Data','Fitted exponential')
title('Data and Fitted Curve')
it should mindestens so:
but in my Matlab it is so:
what should i do? and where am i wrong?

採用された回答

Star Strider
Star Strider 2019 年 10 月 17 日
Choose different values for ‘x0’.
I used these:
x0 = [-2.6; 17; 0.7; 7; 0.0001; -0.7; 0.7];
to get this result:
x =
-4.324990458427486
29.118149115959035
0.816104607520526
6.992507999448133
0.003331267566044
-0.774459180826721
0.700000000000000
and this plot:
#lsqcurvefit fitting not good.png
I began with a random vector, and used fminsearch to produce the new ‘x0’ vector. It gave a good fit after about 10 initial starts. A better approach would have been to use the ga funciton.
  11 件のコメント
Zuyu An
Zuyu An 2019 年 10 月 21 日
I am sorry to ask you again, but my probleme seems still not solved. I submit a new question, Could you please help me?
Star Strider
Star Strider 2019 年 10 月 21 日
I posted an Answer to your new Question.

サインインしてコメントする。

その他の回答 (1 件)

Alex Sha
Alex Sha 2019 年 10 月 18 日
編集済み: Alex Sha 2019 年 10 月 22 日
whether fminsearch or lsqcurvefit in Matlab use local optimization algorithms, it is why the initial start values are so important, unfortunately, guessing good initial start values is nightmare for most of users, although GA toolbox in Matlab use global algorithm, but the effect of GA in Matlab is far below expectations。The follow results are calculated from one of other software by using global optimization, no need to guess initial start values:
Root of Mean Square Error (RMSE): 0.448475537821338
Sum of Squared Residual: 3.21808492838621
Correlation Coef. (R): 0.993866542618332
R-Square: 0.987770704536117
Adjusted R-Square: 0.98588927446475
Determination Coef. (DC): 0.987770704536117
Chi-Square: 0.0996829655505242
F-Statistic: 161.541718751279
Parameter Best Estimate
---------- -------------
x1 -4.32518017924354
x2 1.5161832530864
x3 0.816035356312747
x4 0.139454519659979
x5 0.00333139106331274
x6 -0.015446312666105

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by