MATLAB: How to supply gradient for a nonlinear equality constraint but not for a nonlinear inequality constraint in fmincon

equality constraintfmincongradientnonlinear equality constraint

I'm working on a minimization problem and I have a nonlinear equality constraint ceq(x)=0 and I have supplied gradient Dceq(x). Gradient checks and fmincon performs much better with 'SpecifyConstraintGradient' set to true.
Now, I'd like to add a nonlinear inequality constraint of the form
c(x) <= 0
but I don't know how to compute the gradient Dc(x) analytically. Is there a way to add the inequality constraint c(x) without supplying its gradient while still supplying the gradient Dceq of the equality constraint? It seems that 'SpecifyConstraintGradient' applies to both equality and inequality constraints.
In my situation, fmincon performs poorly without supplying the gradient of the equality constraint. The inequality constraint ceq(x) is a smooth function x, I just don't have an analytic expression for it: ceq(x) is basically – eig(m(x)) where m is a matrix computed smoothly from x.

Best Answer

You could supply your own finite difference approximation for Dc. There are FEX submissions that can facilitate this, e.g.,