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);
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
Best Answer