Refreshment of the objective function with FMINCON

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é

Answers (1)

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 Comments

Thanks Alan,
actually I fixed the problem (probably not the best way, but it still works).
I don't want to interrupt the iteration, refreshing the objective function in the middle of a SQP solving process.
I just want to use different objective functions every time a run a SQP, which is a different target, maybe my explaination was not the best.
The way to change the objective function I have is by updating the variables ys1 and ys2. But the objective function does only allow to introduce values of X.
So what I did was using a matrix for X instead of a vector. A matrix with 3 columns (X, ys1 and ys2). Obviously, ys1 and ys2 must remain always with a fixed value during each SQP solving process, so the associated constraints (in LB and UB) must be left fixed always at the right value each time SQP is executed.
That way I can introduce new values for ys1 and ys2 when a new SQP must be initiated, automatically, without stopping and initializing ys1 and ys2 in the keyboard.
As I said, it is not the most efficient method (certainly you will have better solutions), but it still works.
Regards,
José
That could work even better.
Thanks Walter, I believe this is what I was looking for.
José

Sign in to comment.

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!