Tricky restriction in an optimization problem

6 views (last 30 days)
I will keep the question as general as possible.
I am solving a system of differential-algebraic equations with ode15s and I have an optimization problem, for which I employ the fmincon function. Consider that some parameters of the DAE's will maximize an objective function. This one happens to be the integral of one of the integrated variables across time, say y(17). Thus, we can use the trapz function to calculate the objective function
obj_function = trapz(t, y(:, 17)) % Output of the function given to fmincon
Now comes the tricky part. fmincon can place some restrictions but I want the following one. I would like that, after solving the DAE's, an integral of, consider for example the 4th output variable of the solver y(4) across time is bounded. So we would write
restriction = trapz(t, y(:, 4)); % Restriction that can be calculated only after ode15s is done
And I would like that restriction was bounded, e.g., that it was between 1 and 2.
Is it possible to add this type of restriction so that the parameters to be optimized within fmincon, move as to (1) minimize the objective function, but also (2) keep restriction between said bounds?
Thanks in advance.

Accepted Answer

Mrutyunjaya Hiremath
Mrutyunjaya Hiremath on 17 Aug 2023
'fmincon' is equipped to handle such constraints by accepting a function that provides both equality and inequality constraints. In your case, you want an inequality constraint that keeps the restriction (integral of y(4)) within certain bounds.
Let's break it down:
  1. Objective Function: This remains the same. It would be a function that returns:
  2. Nonlinear Constraints: You'd create another function, say 'myConstraints', that when given the same inputs as your objective function, returns: This is the upper bound. This is the lower bound.
Where c should be less than or equal to 0 for the optimization constraints to be satisfied.
Let's draft the constraints function:
function [c, ceq] = myConstraints(parameters)
% Solve the DAE using the given parameters
% Assuming the DAE's are solved using a function named solveDAE
[t, y] = solveDAE(parameters);
% Inequality constraints
c(1) = trapz(t, y(:, 4)) - 2;
c(2) = 1 - trapz(t, y(:, 4));
% No equality constraints
ceq = [];
Call to fmincon:
x0 = initial_parameters; % starting point
A = []; b = []; % No linear inequality constraints
Aeq = []; beq = []; % No linear equality constraints
lb = lower_bounds; % Lower bounds on parameters
ub = upper_bounds; % Upper bounds on parameters
nonlcon = @myConstraints; % Nonlinear constraints function
[x_optimal, fval] = fmincon(@objectiveFunction, x0, A, b, Aeq, beq, lb, ub, nonlcon);
Where 'objectiveFunction' is another function similar to 'myConstraints' but only returns the value of 'obj_function'.
With this, fmincon will optimize your parameters such that the integral of y(17) is minimized while ensuring that the integral of y(4) remains between 1 and 2.
Bruno Luong
Bruno Luong on 17 Aug 2023
AI surprises me from day to day, but no @Mrutyunjaya Hiremath answer is too good to be AI generated IMO.
I posted much shorter answer but I deleted since @Mrutyunjaya Hiremath answer is much elaborated and helpful.
Julio Maximiliano Ramirez Oyanarte
@Mrutyunjaya Hiremath Thanks for the great response, really sorry for doubting of the AI response, but it was so fast and good.. Also, @Bruno Luong thanks for the information!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!