How to resolve : increase max function value in fitting using fminsearch?
显示 更早的评论
Hi
I was trying to fit my data with fminsearch function with following code:
f = @(a,b,c,x) a - b.*(x).^c;
obj_fun = @(params) norm(f(params(1), params(2), params(3), x) -y);
sol = fminsearch(obj_fun, [1,1,1]);
err = .02*ones(size(x));
errorbar(x,y,err,'horizontal','s',"MarkerFaceColor",[0.8500, 0.3250, 0.0980], ...
"MarkerSize",4,"CapSize",4,"Color",[0.8500, 0.3250, 0.0980],"LineWidth",1)
hold on
x = linspace(min,max,20);
plot(x,f(sol(1),sol(2),sol(3),x),'-',"Color",[0.8500, 0.3250, 0.0980],"LineWidth",1)
hold off
Its getting the fit, but I think this is not best optimum fit its showing following message:
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: 2.586758
it will be realy great if some experties help me here to take care of this. Im attaching data here (data.txt).
Is there any other function which I can use instade of this to fit and better gobal optimazation.
Thank you in advance!
采纳的回答
更多回答(1 个)
If you have the Curve Fitting Toolbox,
[x,y]=readvars('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1034515/data.txt');
ft=fit(x(:),y(:),'power2')
plot(ft,x,y)
5 个评论
Alex Sha
2022-6-17
adding one term "d*x" for fitting function, the result will be much better:
y = a*x^b+c+d*x
Sum Squared Error (SSE): 1.0988630107163
Root of Mean Square Error (RMSE): 0.3494222232194
Correlation Coef. (R): 0.970379925110827
R-Square: 0.941637199058095
Parameter Best Estimate Std. Deviation Confidence Bounds[95%]
--------- ------------- -------------- ----------------------------------
a 430058778433358 0.125126556164325 [430058778433358, 430058778433359]
b 14.4836582099507 3.10784213390318 [6.49469567251403, 22.4726207473875]
c 18.5003218509943 36.6945561128952 [-75.8260375595516, 112.82668126154]
d -257.754044491992 1.5875823760405E-17 [-257.754044491992, -257.754044491992]

Alex Sha
2022-6-17
or the function: y=a*x^b+c+d*exp(e*x);
Sum Squared Error (SSE): 0.798012086224085
Root of Mean Square Error (RMSE): 0.297771740735171
Correlation Coef. (R): 0.978578556003836
R-Square: 0.957615990270552
Parameter Best Estimate Std. Deviation Confidence Interval[95%] (Diff-OK)
--------- ------------- -------------- ----------------------------------
a -3.96448222151296E-7 7.34052972781328E-6 [-2.07770260544974E-5, 1.99841296101948E-5]
b -7.72186291539508 6.95514357122107 [-27.0324372396597, 11.5887114088695]
c -1.28127707754111 12.6536549323532 [-36.4134553773351, 33.8509012222529]
d 286678.994342762 1537623.25203099 [-3982447.55739699, 4555805.54608251]
e -97.6137053829133 77.3303025621153 [-312.317045414963, 117.089634649136]

Somnath Kale
2022-6-17
Matt J
2022-6-17
@Sonnath what is unacceptable about the fit that your current model gives you? You'll notice that both fit() and fminspleas() are in agreement on the fitted parameters.
Somnath Kale
2022-6-17
类别
在 帮助中心 和 File 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!
