MATLAB: How to provide part of the gradient analitically and the other part numerically in fmincon

non-linear programmingoptimization

I am trying to solve a non linear constrained optimization problem with fmincon. I am able to provide analytical gradients for the objective function, the non linear equality constraints and for a subset of the non linear inequality constraints. The matter is that the other subset of the non linear inequality constraints is very complex and I am not able to obtain an analytical expression of its gradient.
Is there a way to tell fmincon for what subset of constraints an analytical gradient will be passed and for the other subset not?
PS: I want to pass an analytical gradient of the first subset because when the other constraints are not considered, computation is much more faster and reliable.

Best Answer

I am sorry, but I do not think that fmincon has the ability to use analytic gradients for a subset of the nonlinear constraints. What you can try to do instead (and this would take a good deal of programming on your part) is to tell fmincon that you are providing analytic gradients for all constraints. Then within the constraints where you do not have the analytic gradients available, compute those gradients (approximately) by finite differences, along the lines of what fmincon would do anyway. That way you will have the benefit of analytic gradients where they are available. But as I said, you would have to call the finite differences yourself within your constraint function.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation