MATLAB: Turn off final Hessian calculation with fminunc or fmincon

fminconfminunchessianMATLABoptimset

I'm using these functions to minimize a problem, with the default algorithm choice for no user-supplied Hessian. For these algorithms, fminunc/fmincon calculate the numerical Hessian at the solution (for other algorithms, it reports the next-to-last-iterate Hessian).
I would like to turn off the calculation of this final Hessian shorten runtime. It is not useful at this particular point in the code. Is it possible to do this?

Best Answer

fmincon and fminunc calculate a Hessian approximation internally in order to solve problems. fmincon does not do any extra calculations to output the Hessian, so there is nothing to do to save time. In any case, the fmincon output Hessian is not very accurate, so there is no reason to ask for it.
However, fminunc can spend extra time computing a finite difference Hessian at the end of its run. So, to save a bit of time, do not ask for a Hessian in the output, and fminunc will not take the time to evaluate one.
Alan Weiss
MATLAB mathematical toolbox documentation