MATLAB: Specifying some but not all Nonlinear Constraint Gradients through Fmincon

fminconMATLABnonlinear constraint gradientsnonlinear constraintsoptimizationOptimization Toolbox

I've been using Fmincon (SQP) for constrained gradient-based optimization, but have been doing so with finite-difference approximations to the nonlinear constraint gradients. I would like to improve the optimization procedure (with regard to optimality and feasibility) by providing analytical derivatives to a small set of nonlinear constraint gradients. Is this possible? If so, how do I tell Fmincon which nonlinear constraint gradients should be approximated by finite-differencing?

Best Answer

I agree, it would be nice if the Optimization Toolbox would expose its finite differencing code as a separate function, so that we could selectively invoke it. Unfortunately, it doesn't allow this. The easiest workaround would probably be to tell fmincon that you will provide all the constraint derivatives analytically. Then, you implement your own finite differencing code within your nonlcon function, for those constraints that you don't truly want to differentiate analytically. You don't have to implement this from scratch. There is finite differencing code on the file exchange that you can build upon, e.g.,