最优化函数fmincon的bug。

这函数给定不同初始点可能求得不同的最优化解也就算了
但为什么解出的相同最优化解对应的目标函数值也不同???
贴上代码
%%%%定义目标函数test20150917%%%%%
function f=test20150917(h)
f=((h-3)^2-4)^2+(h-1)^2;
%%%%%%%%%%%%%%%%%%%%%
%%主函数初值给-1%%%%%
x0=[-1];
options=optimset('Display','off');
[h,f]=fmincon(@test20150917,x0,A,b,[],[],-2,7,[],options);
h
f
%%%%%%%结果%%%%%%%%
h = 1.0000
f = 7.4379e-10
%%主函数初值给-1%%%%%
x0=[3];
options=optimset('Display','off');
[h,f]=fmincon(@test20150917,x0,A,b,[],[],-2,7,[],options);
h
f
%%%%%%%结果%%%%%%%%
h = 1.0000
f = 4.2948e-13
奇葩的最优化

 采纳的回答

yamixa
yamixa 2022-11-18

0 个投票

这个不是bug,你两处fmincon调用给的初值不同,第一处是-1,第二处是3,所以求得的两处的h是不同的,只不过是默认以short型显示,只是你看不到后面的小数位数而已,format long后你就可以看到两处 h的不同了,不同的h代入相同的函数,所得的 f 也就不同了

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 优化 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!