Help with fmincon Optimization for a Function Involving Matrices in MATLAB

2 views (last 30 days)
Hello everyone,
I'm currently working on an optimization problem in MATLAB and could use some help with the fmincon function.
I'm trying to minimize an objective function defined as myfunction = x/(y*z). In my case, y and z are constants and do not change during the optimization process. The variable x is defined by the relationship x = 0.5*a*b + (0.34*c), and I have an additional constraint m = a*b*c.
Here are my constraints:
  • If 1 < y < 5, then:
  • 0.5 < a/b < 2
  • 0.1 < b/c < 1
  • 0.2 < y/m < 1
  • Else if 5 < y < 10, then:
  • 0.2 < a/b < 1.3
  • 0.11 < b/c < 1.31
  • 0.3 < y/m < 1.4
The optimization needs to be run on 50 matrices, each of size 6, I have a excel file, which contain the values for a, b, c, x, y, and z. I want to find out a,b,c to minimize myfunction, actually x value.
My question is two-fold:
  1. How can I set up my fmincon optimization function to exclude y and z from the optimization process since they are fixed values in my large dataset?
  2. How should I approach applying the optimization to the 50 matrices? Should I loop through each one, or is there a more efficient method?
Any help or pointers would be greatly appreciated!
Thank you!
  4 Comments
John D'Errico
John D'Errico on 5 Nov 2023
Sorry, but this makes little sense. You say that y and z are constants. But then have a branch on the value of y.
Next, you say you have a "constraint" that m=a*b*c. But a,b,c are all fixed constants from what you say. But next you say you want to optimize the values of a,b,c. So are a,b,c constant, or are they fixed? What is the point of having values for a,b,c if they are not fixed?
You ask how you can set up the optimization to exclude y and z. That is trivial. Don't vary them! You tell the optimizer what to vary. It makes no decisions for you.
I'm sorry, but your question is totally confusing, which probably means you are confused. But we cannot easily help you if you do not explain the problem clearly enough.
Shariful Islam
Shariful Islam on 5 Nov 2023
Apologies for the confusion earlier. Let me clarify: y and z were indeed mentioned as constants, but that was in reference to their role in a particular part of the problem, not that their values would change during the optimization process.
Regarding a, b, and c, they are not fixed constants. I provided initial values for these variables as a starting point for the optimization process. These values are meant to be adjusted to find the optimal solution. The aim is to vary a, b, and c to satisfy this constraint while optimizing the outcome.
To exclude y and z from the optimization, I meant that they should remain same after the optimization, while the optimizer adjusts the values of a, b, and c. I hope this clarifies my question and I'm open to any suggestions on how to properly set up this optimization.
If you have any queries or need further clarification, please feel free to ask me.
Rageds

Sign in to comment.

Accepted Answer

Torsten
Torsten on 5 Nov 2023
Edited: Torsten on 5 Nov 2023
y = 3;
if y > 1 & y < 5
obj = @(p)0.5*p(1)*p(2)+0.34*p(3);
nonlcon = @(p) deal([],p(4)-p(1)*p(2)*p(3));
A = [0 0 0 0.2;0 0 0 -1;-1 0.5 0 0;1 -2 0 0;0 -1 0.1 0;0 1 -1 0];
b = [y;-y;0;0;0;0];
Aeq = [];
beq = [];
lb = [0;0;0;0];
ub = [Inf;Inf;Inf;Inf];
p0 = [2 4 6 2*4*6];
p = fmincon(obj,p0,A,b,Aeq,beq,lb,ub,nonlcon,optimoptions(@fmincon,'ConstraintTolerance',1e-12))
0.5 <= p(1)/p(2) & p(1)/p(2)<=2
0.1 <= p(2)/p(3) & p(2)/p(3)<=1
0.2 <= y/p(4) & y/p(4)<=1
abs(p(4)-p(1)*p(2)*p(3))<=1e-11
obj(p)
elseif y > 5 & y < 10
% fill in according to case 1
end
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
p = 1×4
1.2173 1.1733 2.1004 3.0000
ans = logical
1
ans = logical
1
ans = logical
1
ans = logical
1
ans = 1.4283
  4 Comments
Shariful Islam
Shariful Islam on 5 Nov 2023
But, y are in constraints. How can I exclude variables frrom the optimization process, if they also are in constraints?
Torsten
Torsten on 5 Nov 2023
Edited: Torsten on 5 Nov 2023
They are constants. As such their numerical values can appear in constraints although they are not variables to be optimized. Look at the code and find the answer.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!