这函数给定不同初始点可能求得不同的最优化解也就算了
但为什么解出的相同最优化解对应的目标函数值也不同???
贴上代码
%%%%定义目标函数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
奇葩的最优化

 Réponse acceptée

yamixa
yamixa le 18 Nov 2022

0 votes

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

Plus de réponses (0)

Catégories

En savoir plus sur 优化 dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!