Help with fmincon Optimization for a Function Involving Matrices in MATLAB
3 views (last 30 days)
Show older comments
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:
- 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?
- 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
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.
Accepted Answer
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
4 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!