2 views (last 30 days)

Show older comments

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
on 12 May 2021

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)

Walter Roberson
on 12 May 2021

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.

Matt J
on 12 May 2021

Edited: Matt J
on 12 May 2021

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)

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

Start Hunting!