# how to plot objective function with variables

35 views (last 30 days)
RAHUL KUMAR on 20 Aug 2019
Answered: Alan Weiss on 22 Aug 2019
xo=[0.0011,0.0049,0.3]; % assumptions
%nvars=3;
A=[];
b=[];
Aeq=[];
beq=[];
lb=[0.001,0.002,0.01]; %lower bound
ub=[0.01,0.08,0.5]; %upper bound
nonlincon = @(x)constraint_new(x); % calling constraint function
Fitnessfun = @(x)weight_testvariable(x); %calling objective function
options = optimoptions(@fmincon,'Display','iter-detailed','Algorithm','sqp','MaxIterations',1500)
options = optimset('Display','iter','TolFun',1e-5)
[X,fval]=fmincon(Fitnessfun,xo,[],[],[],[],lb,ub,nonlincon,options)

Alan Weiss on 22 Aug 2019
You have two definitions of options, meaning the first definition does nothing:
options = optimoptions(@fmincon,'Display','iter-detailed','Algorithm','sqp','MaxIterations',1500) % gets overwritten
options = optimset('Display','iter','TolFun',1e-5)
If you want to plot the objective function value as the optimization runs, set the PlotFcn argument to 'optimplotfval'. If you also want to plot the current point at the same time, set the PlotFcn argument to a cell array, {@optimplotfval,@optimplotx}.
Alan Weiss
MATLAB mathematical toolbox documentation