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

1 次查看(过去 30 天)
华纳公司app下载【hn666.cc】
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 CenterFile Exchange 中查找有关 音频和视频 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!