Refreshment of the objective function with FMINCON

1 次查看(过去 30 天)
Hi, I need to update the objective function in each iteration.
It seems the fmincon function combined with the objective function do not allow to refresh the objective function every iteration.
in the main software I have the options for the fmincon and the command to execute it:
[xsqp]=code(xinic,LB,UB,100,1e-13,1e-13,2.76e-4);
the 'code' function is as fiollows (and it seems I can't add more arguments to refresh the function every iteration:
function [x] = code(x0,lb,ub,MaxIterations_Data,OptimalityTolerance_Data,StepTolerance_Data,DiffMinChange_Data)
%% This is an auto generated MATLAB file from Optimization Tool.
%[x,fval,exitflag,output,lambda,grad,hessian]
%% Start with the default options
options = optimoptions('fmincon');
%% Modify options setting
options = optimoptions(options,'Display', 'off');
options = optimoptions(options,'MaxIterations', MaxIterations_Data);
options = optimoptions(options,'OptimalityTolerance', OptimalityTolerance_Data);
options = optimoptions(options,'FunctionTolerance', OptimalityTolerance_Data);
options = optimoptions(options,'StepTolerance', StepTolerance_Data);
options = optimoptions(options,'Algorithm', 'sqp');
options = optimoptions(options,'DiffMinChange', DiffMinChange_Data);
options = optimoptions(options,'FiniteDifferenceType', 'central');
[x] = ...
fmincon(@fobjetivoTGA,x0,[],[],[],[],lb,ub,@nonlcon,options);
Then, the objective function is as follows:
function [m,gm]=fobjetivoTGA(X)
Tt41min=1300;
Tt41max=1400;
Tt42min=1450;
Tt42max=1550;
Tt41=Tt41min+(X(11))*(Tt41max-Tt41min)/2;
Tt42=Tt42min+(X(12))*(Tt42max-Tt42min)/2;
d=1e-4;
[f1]=finter(X,Tt41);
[f2]=finter(X,Tt42);
m=sqrt(((norm(f1-ys1))^2)+((norm(f2-ys2))^2));
finter is another function, it gives no problem because it uses the info on X.
I need to introduce ys1 and ys2 in every iteration, refreshed, but I do not find the way.
Could you please help me with this?
Thanks
José

回答(1 个)

Alan Weiss
Alan Weiss 2021-9-27
I think that you have a mistaken view of what fmincon does. All optimization solvers take a fixed objective function and iterate to find a local minimum of that objective function. In general, you are not allowed to change the objective function definition in the middle of an optimization.
I do not understand your application. It is possible that you are looking for a different kind of algorithm, not an optimization algorithm but instead a control system that helps you track a changing target. Are you looking for a PID controller?
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  3 个评论
José Rodrigo Ramírez
That could work even better.
Thanks Walter, I believe this is what I was looking for.
José

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by