Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.
38 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello I am really new both with matlab and optimization problems, but I have been several hours trying to fix this and I am really lost.
I get that answer with every code i tried, I really would appreciate any help.
******The extra file I created for the non linear constrain has this:
function [ineq_cons,eq_cons]= constraint_Ejercicio20(x)
ineq_cons =[(x(1)^2 + (x(2)^2 - 4];
eq_cons =[];
*******The main code is this:
fun_max = @(x) - x(1) * (x(2));
A = [-1,-2;
-1,0;
0,-1];
b = [-2, 0, 0];
Aeq = [];
beq = [];
cons = @constraint_Ejercicio20;
lb = [];
ub = [];
> x0 = [0;
0];
[x_max,fval_max,exitflag,output,lambda_max] = fmincon(fun_max,x0,A,b,Aeq,beq,lb,ub,cons);
*********And the problem i need to solve is this
% Opt: q(x,y)= x*y
% S.t.
% x^2+y^2 <= 4
% x+2y >= 2
% x >= 0
% y >= 0
Thanks in advace
0 commentaires
Réponses (1)
Alan Weiss
le 15 Déc 2020
You did a good job converting the problem to code. Your only real errors are typos in the nonlinear constraint function. Try this:
function [ineq_cons,eq_cons]= constraint_Ejercicio20(x)
ineq_cons = x(1)^2 + x(2)^2 - 4;
eq_cons = [];
end
Let me also say that your linear constraints, while correct, should only have one row in A and one entry in b. The second and third rows are better expressed as lower bounds, lb.
Alan Weiss
MATLAB mathematical toolbox documentation
0 commentaires
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!