如何改下边的代码?可以输出变量x1和x2每次的迭代值。大神。
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!