MATLAB Answers

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

25 views (last 30 days)
David Ogayar
David Ogayar on 15 Dec 2020
Answered: Alan Weiss on 15 Dec 2020
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 Comments

Sign in to comment.

Answers (1)

Alan Weiss
Alan Weiss on 15 Dec 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 Comments

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!