How to record the function value for each iteration with using fmincon function.
이전 댓글 표시
clc, clear all
%Inıtial Guess
x0=[1,6];
%%
%Lower and upper bounds
LB=[-inf];
UB=[10];
%%
%fmincon function
[x,fval]=fmincon(@objfun,x0,[],[],[],[],LB,UB,@confun,[]);
%%
%Constraint Function
function [c,ceq]=confun(x)
%inequality constraints
c=[x(1)+x(2)-5];
%equality constraints
ceq=[];
end
%%
%Object Function
function [f]=objfun(x)
f=(x(1)^2-5*x(2));
end
댓글 수: 4
Walter Roberson
2021년 11월 22일
Ok, suppose that you had the values. What would you do with them?
IBRAHIM BOZTAS
2021년 11월 22일
Walter Roberson
2021년 11월 23일
Have you considered using the option for 'display', 'iter' ?
Have you considered using the option for 'plotfcn' so that the values are plotted during the calculation?
Alan Weiss
2021년 11월 23일
편집: Alan Weiss
2021년 11월 23일
You might want to give 2-D bounds. You have a 2-D variable, but give bounds only on the first component.
These examples might also be of interest: Example of a Nested Output Function (uses base MATLAB) or for fmincon see Output Functions for Optimization Toolbox™.
Alan Weiss
MATLAB mathematical toolbox documentation
답변 (0개)
카테고리
도움말 센터 및 File 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!