MATLAB: How to correctly specify fmincon nonlinear constraints

fminconnonlinear constraintsOptimization Toolbox

Since the fmincon cin(x) and ceq(x) nonlinear function constraints have to return vectors, what happens when thse functions return a scalar value? Is the scalar used to create a correctly sized vector filled with the scalar value? See example code below:
function [cin, ceq] = nonlcon(x)
cin = -1;
ceq = x'*H*x - sd.^2; % where H and sd are global.
end

Best Answer

The lengths of the vectors cin and ceq tell fmincon how many inequality and equality constraints you have. So, if they are scalars (i.e., vectors of length 1) then fmincon will assume that you have only 1 inequality and equality constraint. Moreover, those constraints will be considered satisfied if and only if x results in cin<=0 and ceq==0 (up to the ConstraintTolerance parameter you have set).