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

조회 수: 4 (최근 30일)
Matthew Hunt
Matthew Hunt 2020년 4월 23일
댓글: Alan Weiss 2020년 5월 11일
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개)

Alan Weiss
Alan Weiss 2020년 4월 24일
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
Matthew Hunt
Matthew Hunt 2020년 5월 11일
The documentation for matlab typically is a mess for things like this. Some of it is out of date and you have to see other people's code to figure out what to do.
I have since found some code which works.
Alan Weiss
Alan Weiss 2020년 5월 11일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by