我尝试在 fmincon 优化器中施加非线性约束。问题是非线性约束应该仅在参数之一为负时才相关。代码是这样的:
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
问题是,例如,当使用诊断选项时,Matlab 说没有非线性约束:
Constraints
Number of nonlinear inequality constraints: 0
Number of nonlinear equality constraints: 0
并且在寻找最优值的过程中也违反了这种非线性约束。有人可以指出我是否没有正确定义非线性条件约束吗?