这函数给定不同初始点可能求得不同的最优化解也就算了
但为什么解出的相同最优化解对应的目标函数值也不同???
贴上代码
%%%%定义目标函数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에서 优化에 대해 자세히 알아보기

태그

질문:

2022년 11월 18일

답변:

2022년 11월 18일

Community Treasure Hunt

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

Start Hunting!