如何改下边的代码?可​以输出变量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!