Optimization of objective function with multiple constraints and variables
Mostra commenti meno recenti
I need to minimize an objective function with four variables. The function is to be optimized under 6 nonlinear inequalities, as well as lower and upper bounds.
My basic script is this:
P = 6000;
E = 30e6;
G = 12e6;
L = 14;
fun=@(x) (1+0.10471)*x(1)*x(2)+0.04811*x(3)*x(4)*(L+1);
gs = GlobalSearch;
opts = optimoptions(@fmincon,'Algorithm','interior-point');
problem = createOptimProblem('fmincon','x0',[0.1,0.1,0.1,0.1],'objective',fun,'lb',[0.125,0.1,0.1,0.1],'ub',[5,10,10,5],'nonlcon',nonlcon,'options',opts);
where
function [c,ceq] = nonlcon(~)
P = 6000;
E = 30e6;
G = 12e6;
L = 14;
c =@(x) [-13600 + sqrt((P/(sqrt(2)*x(1)*x(2)))^2+2*(P/(sqrt(2)*x(1)*x(2)))*((P*(L+x(2)/2))*(sqrt((x(2)^2)/4+...
((x(1)+x(3))/2)^2)))/(2*(sqrt(2)*x(1)*x(2)*((x(2)^2)/12+((x(1)+x(3))/2)^2))))*x(2)/(2*(sqrt((x(2)^2)/4+...
((x(1)+x(3))/2)^2)))+((P*(L+x(2)/2))*(sqrt((x(2)^2)/4+...
((x(1)+x(3))/2)^2)))/(2*(sqrt(2)*x(1)*x(2)*((x(2)^2)/12+((x(1)+x(3))/2)^2)))^2;
-30000+(6*P*L)/(x(4)*x(3)^2);x(1)-x(4);0.10471*x(1)^2+0.04811*x(3)*x(4)*(14+x(2))-5;...
0.125-x(1);(4*P*L^3)/(E*x(4)*x(3)^3)-0.25; P-4.013*E*sqrt((x(3)^2*x(4)^6)/36)*(1-x(3)*sqrt(E/(4*G))/(2*L))/(L^2)];
ceq = [];
end
Up until that point, my script runs with no issues. However when I try to insert a way to run the problem and display some results I get errors. One way I tried is
min=run(gs,problem);
and I get
Error using fmincon (line 626)
The constraint function must return two outputs; the nonlinear inequality constraints and the nonlinear equality constraints.
Error in globalsearchnlp
Error in GlobalSearch/run (line 340)
globalsearchnlp(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON,options,localOptions);
Error in confuneq1 (line 23)
min=run(gs,problem);
Caused by:
Failure in initial call to fmincon with user-supplied problem structure.
And another one I tried is
sol=solve(problem);
and I get
Error using char
Conversion to char from struct is not possible.
Error in solve>isOption (line 459)
b = ~isa(a, 'logical') && any(strcmpi(char(a), ...
Error in solve>getEqns (line 392)
while k <= numel(argv) && ~isOption(argv{k})
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
Error in confuneq1 (line 22)
sol=solve(problem);
I would appreciate some help. I don't know if the problem creation is wrong, or the ways I try to run it, or both. Thanks
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Solver-Based Nonlinear Optimization in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!