如何改下边的代码?可​以输出变量x1和x2​每次的迭代值。大神。

1 回表示 (過去 30 日間)
华纳公司app下载【hn666.cc】
华纳公司app下载【hn666.cc】 2022 年 10 月 26 日
function runfmincon
x(1)=[];
x0 = [1 36];
options = optimset('outputfcn',@outfun,'display','iter','Algorithm','active-set');
xsol = fmincon(@objfun,x0,[],[],[],[],lb,ub, options)
x(1)%各次迭代的自变量
function stop = outfun(x,optimValues,state)
stop = false;
switch state
case 'iter'
x(1) = [ x(1); x];
end
end
function f = objfun(x)
f=0.4022-7.4630*x(1)+10.6247*x(2)-0.6351*x(1)^2+11.9797*x(2)^2-17.3124*x(1)*x(2) +0.2085*x(1)^2*x(2)-3.9589*x(1)*x(2)^2+5.7393*x(1)^2*x(2)^2;
end
lb=[0.4,12];
ub=[1.6,60];
end
end

回答 (0 件)

カテゴリ

Help Center および File Exchange音频和视频 についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!