fmincon contraints range issue

조회 수: 2 (최근 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