![#lsqcurvefit fitting not good.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/243217/#lsqcurvefit%20fitting%20not%20good.png)
lsqcurvefit fitting not good
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
>> 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/243211/image.png)
but in my Matlab it is so:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/243213/image.png)
what should i do? and where am i wrong?
0 Commenti
Risposta accettata
Star Strider
il 17 Ott 2019
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/243217/#lsqcurvefit%20fitting%20not%20good.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 Commenti
Più risposte (1)
Alex Sha
il 18 Ott 2019
Modificato: Alex Sha
il 22 Ott 2019
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/243270/image.jpeg)
0 Commenti
Vedere anche
Categorie
Scopri di più su Historical Contests in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!