Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.
조회 수: 33 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Alan Weiss
2020년 12월 15일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!