fmincon contraints range issue

1 次查看(过去 30 天)
ayman mounir
ayman mounir 2021-1-11
回答: Alan Weiss 2021-1-11
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

回答(1 个)

Alan Weiss
Alan Weiss 2021-1-11
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

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by