It seems to me that if you are changing the problem Hessian at each iteration then you will have to change the fmincon Hessian at each iteration. You can save time by simply updating the options instead of creating all-new options:
options = optimoptions('fmincon','Algorithm','interior-point','SpecifyConstraintGradient',true,'SpecifyObjectiveGradient',true);
for i=1:maxIter
z = ones(Elements,1)*i;
hess = @(x,lambda) analyticHessian(x,lambda,z);
options.HessianFcn = hess;
x = fmincon(costfun,x_0,[],[],[],[],[],[],@constraints,options);
end
Or you could use a nested function instead of an anonymous function for carrying the extra parameter. See Passing Extra Parameters. Alan Weiss
MATLAB mathematical toolbox documentation
Best Answer