Using fmincon and m-files

Trying to minimize f(x,y)=x^4-x^2+y^2-2x+y
with linear inequality x+y <= 0 and nonlinear inequality x^2+y^2 <= 1
my code
========================================================
(in workspace)
objfun=@(x) x(1)^4-x(1)^2+x(2)^2-2*x(1)+x(2);
x0 = [1;-1];
[x,fval]=fmincon(objfun,x0,[1,1],0,[ ],[ ],[ ],[ ],'constraint')
(in m.file ...constraint.m)
function [c,ceq]=constraint(x)
c1=x(1)^2+x(2)^2-1;
ceq=[ ]
===========================================================
Running the code gives:
Warning: The default trust-region-reflective algorithm does not solve problems with the constraints you have specified. FMINCON will use the active-set algorithm instead. For information on applicable algorithms, see Choosing the Algorithm in the documentation.
> In fmincon at 486
Error using feval
Undefined function 'constaint' for input arguments of type 'double'.
Error in fmincon (line 681)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Caused by:
Failure in initial user-supplied nonlinear constraint function
evaluation. FMINCON cannot continue.
WHY IS THIS HAPPENING?!

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by