MATLAB: Cannot supply fmincon with Hessian

fminconhessianOptimization Toolbox

I am trying to help fmincon to converge faster by supplying gradient vector and Hessian matrix. I am using interior-point algorithm and I realize that in such case, I have to supply Hessian using a call to another function which is assigned to HessFcn of my OPTIOINS. I also realize that the Hessian for fmincon is the second derivatives of the Lagrangian as described here in equation 14-1. I am supposed to use the following function definition to have access to my fitting parameters and lambda while calculating the hessian
hessian = hessianfcn(x, lambda)
From this point on I have some difficulties figuring out the procedure. First of all how should I calculate the second and third terms in equation 14-1? Also, although my problem is constrained, lambda structure is empty i.e. whenever I try to access it from hessianfcn, it returns:
lambda =
eqnonlin: [0x1 double]
ineqnonlin: [0x1 double]
Any idea how to fix this problem and also how to calculate second and third terms in equation 14-1?

Best Answer

The second and third terms sum over the Hessians of your constraints (weighted by the corresponding lambda). Essentially, you need to be computing the Hessian of your ceq(i) and c(i) as well as the Hessian of your objective, f, inside the HessFcn. Then you need to apply the lambda(i) as weights to all those Hessians and sum them all up.
Why the lambda structure is empty is not something we can determine without seeing code. My guess is that you defined a nonlcon function for your nonlinear constraints, but neglected to actually pass it to fmincon. Or, your input arguments to fmincon are not in the proper sequence.