MATLAB: Not enough input arguments is showing when a simple “fmincon” code is ran, anyone please help

not enough input arguments

options = optimoptions('fmincon','Display','iter','Algorithm','sqp');
fun = @(x)sum((x.*(log(x))));
A = [];
b = [];
lb = [0,0,0,0,0];
ub = [1,1,1,1,1];
Aeq = [1,1,1,1,1;0,1,2,3,4];
beq = [1;3];
x0 = [.2 .2 .2 .2 .2];
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlinfn,options);
display(x)
where the non linear function is:
function [c,ceq] = nonlinfn(x)
c = [];
ceq = sum(x.*x)-1;
If
ceq = @(x)sum(x.*x)-1
is used, gives a result but the results is same if we don't use the non linear constraint. Now why arguments are few?

Best Answer

Your error is that your fmincon call uses nonlinfn instead of the function handle @nonlinfn:
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,@nonlinfn,options); % this avoids the error
I am afraid that, when I tried running the corrected code, it converged to an infeasible point. Your problem may not be well-formulated. At the least, try giving analytic gradient and maybe Hessian.
Alan Weiss
MATLAB mathematical toolbox documentation