Fmincon - Variable dependent constraints

2 次查看(过去 30 天)
Hello,
I'm sorry if this question has already been answered.
I want to find the minimum of a function of three variables f(x,y,z), where the constraints of the variables are defined as follows (for example) :
  • 1 < x < 2
  • x/20 < y < x/10
  • 2y < z < x/5
I would be greatful if someone could help me about how to define this by using the fmincon function.
Thanks in advance!

采纳的回答

Walter Roberson
Walter Roberson 2021-5-12
lb = [1, 1/20, 2/20]; ub = [2, 2/10, 2/5];
A = [
1/20, -1, 0
-1/10, 1, 0
0, 2, -1
-1/5, 0, 1
]
b = [
0
0
0
0
]
Aeq = []; beq = [];
xyz = fmincon(@OBJECTIVE, A, b, Aeq, beq, lb, ub)
Unless, that is, you need your endpoints to be strict inequalities. If you do, b would end up containing some +/- eps(realmin)
  4 个评论
BraF
BraF 2021-5-12
Everything is clear now, thanks a lot to both of you!
And just to make sure, lb and ub are correctly defined now (with these new constraints) ?
I've got lb = [0.05, 0.05/30, 5/30], ub = [0.5, 0.5/10, 0.5/4].
Walter Roberson
Walter Roberson 2021-5-12
编辑:Walter Roberson 2021-5-12
You have x/30 < y < x/10 so if the lower bound for x is 0.05 then the lower bound for y is (as you calculated) 0.05/30 . But then you have 5y < z < x/4 so you should take 5 times the y lower bound as the z lower bound, which would get you to 5*0.05/30
Upper bound, x is max 0.5, y is up to x/10 which would be 0.5/10 (as you calculated). z upper bound is up to x/4 and x is up to 0.5, so z upper bound would be 0.5/4 (as you calculated)
So you were mostly right, but your lower bound on z was wrong.

请先登录,再进行评论。

更多回答(1 个)

Matt J
Matt J 2021-5-12
编辑:Matt J 2021-5-12
If you wish, you can download prob2matrices() and use the problem-based framework to help set up the linear constraints.
x=optimvar('x','LowerBound',1, 'UpperBound',2);
y=optimvar('y');
z=optimvar('z');
con.xyleft= x/20<=y;
con.xyright= y<=x/10;
con.yzleft= 2*y <= z;
con.yzright= z<=x/5;
[S,idx]=prob2matrices({x,y,z}, 'Constraints',con);
xyz=fmincon(@objective, [x0,y0,z0], S.Aineq,S.bineq,S.Aeq,S.beq,S.lb,S.ub)

Community Treasure Hunt

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

Start Hunting!

Translated by