fmincon contraints range issue

1 visualización (últimos 30 días)
ayman mounir
ayman mounir el 11 de En. de 2021
Respondida: Alan Weiss el 11 de En. de 2021
Hello everyone,
In case i need the surface ares as written in the constraint(c=area_surf(x)-10). In case i want to be between 10 and 5, I have tried to add & conditio but there was an error.
how should i write it?
Thanks in advance
Ayman
unction y = fcn(x)
% L_G=1;
% W_G=1;
% H_G=1;
% X0=[ L_G W_G H_G 5 6 ]
X0=[x];
xopt=fmincon(@objective,X0,[],[],[],[],[],[],@contraints)
v=calcvolume(xopt)
a=area_surf(xopt)
function volume= calcvolume(x)
L=x(1);
W=x(2);
H=x(3);
volume= L*W*H
end
function surface= area_surf(x)
L=x(1);
W=x(2);
H=x(3);
surface = 2*L*H + 2*L*W + 2*W*H;
end
function obj =objective(x)
obj=-calcvolume(x)
end
function [c, ceq]= contraints(x)
c=area_surf(x)-10
ceq=[];
end

Respuestas (1)

Alan Weiss
Alan Weiss el 11 de En. de 2021
You simply need two constraints, area_surf < 10 and area_surf > 5.
function [c, ceq]= contraints(x)
c(2) = area_surf(x) - 10;
c(1) = 5 - area_surf(x);
ceq = [];
end
Alan Weiss
MATLAB mathematical toolbox documentation

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by