How do I include a user specified hessian function for fmincon?
11 views (last 30 days)
Show older comments
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:
options = optimoptions('fmincon','SpecifyObjectiveGradient',true,'HessFcn','objective','Display','iter','OutputFcn',@outfun);
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)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
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);
G=grad_F(T_data,t,R,X,Joule);
Temp=cylinder_temp(t,R,X,Joule);
T=Temp(:,end);
T_theta=theta_grad(t,R,X,Joule);
T_kappa=kappa_grad(t,R,X,Joule);
T_hop=h_grad(t,R,X,Joule);
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?
1 Comment
Answers (1)
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 Comments
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
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!