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

조회 수: 3 (최근 30일)
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 CenterFile Exchange에서 Solver 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