fmincon contraints range issue
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Alan Weiss
on 11 Jan 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
0 Comments
See Also
Categories
Find more on Mathematics and Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!