Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.

38 次查看(过去 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

回答(1 个)

Alan Weiss
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

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by