Optimization of a function with constraints containing 15 variables
Afficher commentaires plus anciens
I am trying to solve an optimization problem of a function to find its minimum value that satisfies some constraints ( linear and nonlinear equalities; linear inequalities). So far, I have tried the following solvers:
- fmincon (algorithms interior-point, active-set and sqp). The function converges for some initial values and deteriorates for other initial values that are only slightly different.
- ga. Either the algorithm doesn't find a feasible point in the first iteration (slighty less frequent when using nonlinear feasible creation function) or when it does, the stall generations limit is exceeded without a solution beeing found.
My code for the objective function:
function val = objFun(x)
val = x(1)+x(2)+x(3)+x(4);
end
My code for the constraints:
function [c, ceq] = constraints(x)
%inequalities
c(1) = -x(1);
c(2) = -x(2);
c(3) = -x(3);
c(4) = -x(4);
c(5) = x(15)-0.3;
%linear equalities
ceq(1) = x(5)+x(6)+x(7)+x(8);
ceq(2) = -500+x(9)+x(10)+x(11)+x(12);
ceq(3) = -500*0.636-0.25*(x(4)-x(2));
ceq(4) = -0.25*(x(3)-x(1));
ceq(5) = -500*0.242-0.25*(x(8)-x(6))-a*(x(11)-x(9));
ceq(6) = x(1)+x(3)-x(2)-x(4);
ceq(7) = (x(9)/x(5))+((0.25-x(13))/(-x(14)));
ceq(8) = (x(10)/x(6))+((-x(13))/(-0.25-x(14)));
ceq(9) = (x(11)/x(7))+((-0.25-x(13))/(-x(14)));
ceq(10) = (x(12)/x(8))+((-x(13))/(0.25-x(14)));
%nonlinear equalities
ceq(11) = x(15)^2*x(1)^2-x(5)^2-x(9)^2;
ceq(12) = x(15)^2*x(2)^2-x(6)^2-x(10)^2;
ceq(13) = x(15)^2*x(3)^2-x(7)^2-x(11)^2;
ceq(14) = x(15)^2*x(4)^2-x(8)^2-x(12)^2;
end
My code for the optimization with fmincon:
options = optimoptions(@fmincon,'Display','iter','Algorithm','sqp');
x0 = [300 400 300 200 100 400 100 200 500 400 200 100 0.1 0.1 0.25]; %this initial value converges
% x0 = [300 400 300 200 110 400 100 200 500 400 200 100 0.1 0.1 0.25]; %this initial value deteriorates
[x,fval] = fmincon(@objFun,x0,[],[],[],[],[],[],@constraints,options)
My code for the optimization with ga:
options = gaoptimset('Display','iter','CreationFcn',@gacreationnonlinearfeasible);
[x,fval] = ga(@objFun,15,[],[],[],[],[],[],@constraints,options)
2 commentaires
Dhanu Naik
le 30 Jan 2018
How can we tell Constraint function,The number of decision Variables in case of Generic Programming. Here you have taken 15 which was known to you,if my number of decision variables varies,how can I send that extra information to constraint function.
Walter Roberson
le 30 Jan 2018
You can take the length() of the input to the constraint function. If somehow you have a different number of decision variables, then use http://www.mathworks.com/help/matlab/math/parameterizing-functions.html
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!