How can I save the value of each decision variable in each iteration in using fmincon MATLAB

3 ビュー (過去 30 日間)
NooshinY
NooshinY 2017 年 11 月 16 日
コメント済み: NooshinY 2017 年 11 月 16 日
I uesed this code to find the optimal value of 3 decision variables, But I want to plot the optimization process, and I need the value of each decision variable in each iteration,
x0=[1;1;1]; % Starting guess
lb=[0.5;0.5;0.5];
ub=[1.25;1.27;4];
options = optimoptions('fmincon','Display','iter','Algorithm','interior-point','Tolx',1e-15,'Tolfun',1e-16,'MaxFunEvals',600,'MaxIter',100);
[x,fval,exitflag,output]=fmincon(@optim,x0,[],[],[],[],lb,ub,[],options)
When I used ,'outputfcn',@outfun, in the options I get error
is there any way that I can check the value of decision variables in each iteration?
  5 件のコメント
NooshinY
NooshinY 2017 年 11 月 16 日
history.fval=[];
optimValues.fval=[];
searchdir=[];
function stop =outfun(x,optimValues,state)
stop = false;
switch state
case 'init'
hold on
case 'iter'
% Concatenate current point and objective function
% value with history. x must be a row vector.
history.fval = [history.fval; optimValues.fval];
history.x = [history.x; x];
% Concatenate current search direction with
% searchdir.
searchdir = [searchdir;...
optimValues.searchdirection'];
plot(x(1),x(2),'o');
% Label points with iteration number and add title.
% Add .15 to x(1) to separate label from plotted 'o'
text(x(1)+.15,x(2),...
num2str(optimValues.iteration));
title('Sequence of Points Computed by fmincon');
case 'done'
hold off
otherwise
end
end
NooshinY
NooshinY 2017 年 11 月 16 日
I have the above function for outfun in the path. but I still get error

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by