I try to impose a nonlinear constraint in the fmincon optimizer. The problem is that the nonlinear constraint should be relevant only when one of the parameters is negative. The code is like this:
function [c, ceq] = confun_Model11(param)
% Nonlinear inequality constraints: c(x)<=0
if param(6)<0
c = (-4)*param(5)*param(7) + param(6)^2+eps;
else
c = [];
end
%Nonlinear equality constraints: ceq(x)=0
ceq = [];
end
The problem is that for example when using the diagnostics option Matlab says that there are no nonlinear constrains:
Constraints
Number of nonlinear inequality constraints: 0
Number of nonlinear equality constraints: 0
and also during the search for the optimum this nonlinear constraint is violated. Can somebody please indicate if I have not properly defined the nonlinear conditioned constraint?