フィルターのクリア

How to resolve : increase max function value in fitting using fminsearch?

6 ビュー (過去 30 日間)
Somnath Kale
Somnath Kale 2022 年 6 月 16 日
編集済み: Matt J 2022 年 6 月 18 日
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!

採用された回答

Matt J
Matt J 2022 年 6 月 16 日
編集済み: Matt J 2022 年 6 月 16 日
You could do as the message says and increas MaxFunEvals, but for your model, it would be better to download fminspleas,
[x,y]=readvars('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1034515/data.txt');
funlist={1,@(c,xd) -xd(:).^c};
[c,ab]=fminspleas(funlist, 1 ,x, y);
sol=[ab(:).',c]
sol = 1×3
-6.5546 -0.0000 -6.0133
  2 件のコメント
Somnath Kale
Somnath Kale 2022 年 6 月 17 日
@Matt J thank you for your response!
Can you little bit elaborate the code, means fminsplease function and how your calculation that will be god to understand me as well!
Matt J
Matt J 2022 年 6 月 17 日
編集済み: Matt J 2022 年 6 月 18 日
Fminspleas uses a technique which only needs to iterate over the c parameter, so it is an easier search.

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

その他の回答 (1 件)

Matt J
Matt J 2022 年 6 月 16 日
編集済み: Matt J 2022 年 6 月 16 日
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')
ft =
General model Power2: ft(x) = a*x^b+c Coefficients (with 95% confidence bounds): a = 1.124e-06 (-2.414e-05, 2.639e-05) b = -6.015 (-14.64, 2.609) c = -6.554 (-9.987, -3.121)
plot(ft,x,y)
  5 件のコメント
Matt J
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
Somnath Kale 2022 年 6 月 17 日
@Matt J Im more intrested in fitting coefficint than that the good visual fit. I tried with fminplease it doing the job!
Thanks! looking forword to your help in future as well!

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

カテゴリ

Help Center および File ExchangeLeast Squares についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by