Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

How can solve constrait optimization?

1 visualización (últimos 30 días)
Sinem Senel
Sinem Senel el 4 de Ag. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi everyone, I have constrait optimizatıon problem. I am trying to maxımize x, y and z. And some of my constrait are like that
0.2<=y
0.2<= x
0.2<=z<=2
x+y<=z
How can ı express the lass constrait ın matlab? Using A, b ,x0

Respuestas (2)

Walter Roberson
Walter Roberson el 4 de Ag. de 2020
A = [1 1 -1] b = 0 for A*X <= b, where X = [x; y; z], expresses x+y-z<=0 , which is x+y<=z
Your other constraints that you posted should be expressed as lb = [0.2, 0.2, 0.2], ub = [inf, inf, 2]
  3 comentarios
Walter Roberson
Walter Roberson el 4 de Ag. de 2020
what is your code?
Walter Roberson
Walter Roberson el 6 de Ag. de 2020
You can do a bit better by adjusting the tolerance
fun = @(x)-((1-x(1)-x(2))+ log(x(1))+log(x(2)));
lb = [0.2, 0.2,0.2];
ub = [inf,inf,2];
A = [1,1,-1];
b = [0];
Aeq = [];
beq = [];
x0 = [1/4,1/4,1.1];
nonlcon = [];
options = optimoptions('fmincon','Algorithm','interior-point',...
'OptimalityTolerance',1e-20, ...
'StepTolerance', 1e-20, ...
'ConstraintTolerance', 1e-20, ...
'Display', 'iter' );
[x, fval] = fmincon(fun, x0, A, b, Aeq, beq, lb, ub, nonlcon, options);
disp(x)
disp(fval)
The OptimalityTolerance is the only one that I found made a difference.
Unfortunately the function calls into barrier.p so I cannot trace to find out exactly why it is ending the optimization.

Sinem Senel
Sinem Senel el 5 de Ag. de 2020
fun = @(x)-((1-x(1)-x(2))+ log(x(1))+log(x(2)));
lb = [0.2, 0.2,0.2];
ub = [inf,inf,2];
A = [1,1,-1];
b = [0];
Aeq = [];
beq = [];
x0 = [1/4,1/4,1.1]
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
%this is my entire code, i use x(2) as y variable and x(3) as z variable.

Community Treasure Hunt

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

Start Hunting!

Translated by