# How do I include a user specified hessian function for fmincon?

23 views (last 30 days)
Matthew Hunt on 23 Apr 2020
Commented: Alan Weiss on 11 May 2020
I am working on an optimisation code and I have a Hessian function I wish fmincon to use. I'm currently having trouble trying to get the correct command to include the Hessian. I am currently using:
For which I get the following error:
> In Temperature_inverse_problem (line 51)
Error using feval
Undefined function or variable 'objective'.
Error in computeHessian
Error in barrier
Error in fmincon (line 813)
barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in Temperature_inverse_problem (line 53)
X=fmincon(t_fun,X_old,A,b,Aeq,beq,LB,UB,[],options);
The code for my objective function is:
function [Y,G,H] = Boundary_temperature(T_data,t,R,X,Joule)
%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
diff=battery_temp(t,R,X,Joule)-T_data;
integrand=0.5*(diff.^2);
Y=trapz(t,integrand);
Temp=cylinder_temp(t,R,X,Joule);
T=Temp(:,end);
T_t=T_theta(:,end);
T_k=T_kappa(:,end);
T_h=T_hop(:,end);
H=Hessian_F(T_data,t,R,X,Joule,T,T_t,T_k,T_h);
end
Here Y is the objective function, G is the gradient and H is the Hessian. I've trolled the internet and I've not found anything which works. What am I doing wrong?
Ameer Hamza on 23 Apr 2020
How is t_fun defined in the call to fmincon.

Alan Weiss on 24 Apr 2020
If you read the documentation for Including Gradients and Hessians, you will see that the fmincon 'interior-point' algorithm does not allow you to use 'HessFcn'='objective'. Instead, you must write a Hessian function that is the Hessian of the Lagrangian. See Hessian for fmincon interior-point algorithm.
Alan Weiss
MATLAB mathematical toolbox documentation
##### 2 CommentsShowHide 1 older comment
Alan Weiss on 11 May 2020
I try very hard to keep the documentation clear, correct, and concise. If you ever find anything incorrect or unclear, please let me know either by emailing me directly or filing a bug report (we consider documentation errors to be bugs).
Alan Weiss
MATLAB mathematical toolbox documentation

R2018a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!