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 have only inequality constraint (C). it is in quadratic form.
gbee_r_i,p_in,nel,nhp are known matrices or variables.
I define constraint as below:
function [ c,ceq,DC,DCeq] = cond5( x,gbee_r_i,p_in,nel,nhp)
nn=0;
bb=0;
for i=1:nel
for j=1:nhp
nn=nn+1;
bb(nn,:)=1*x'*(gbee_r_i(:,:,j,i))'*p_in*gbee_r_i(:,:,j,i)*x;
rr(:,nn)=(gbee_r_i(:,:,j,i))'*p_in*gbee_r_i(:,:,j,i)*x;
end
end
DCeq=[];
DC=rr;
ceq=[];
c=bb;
end
Define options like this:
options = optimoptions(@fmincon,...
'GradObj','on','GradConstr','on','Hessian','user-supplied',...
HessFcn',@(x)hessinterior(x,lambda,gbee_r_i,p_in,nel,nhp),'Display',...
'iter','Algorithm','interior-point','maxFunEvals',20000000000000,'MaxIter',5000,'TolFun',1e-3);
`@(x)hessinterior(x,lambda,gbee_r_i,p_in,nel,nhp)
is HessFcn and is defined as below.
function [ h ] = hessinterior(x,lambda,gbee_r_i,p_in,nel,nhp)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
nn=0;
h=0;
for i=1:nel
for j=1:nhp
nn=nn+1;
h=h+lambda.ineqnonlin(nn)*(gbee_r_i(:,:,j,i))'*p_in*gbee_r_i(:,:,j,i);
end
end
end
after running the program this error is shown
Error using @(x)hessinterior(x,lambda,gbee_r_i,p_in,nel,nhp)
Too many input arguments.Error in C:\Program Files\MATLAB\R2013a\toolbox\optim\optim\private\computeHessian.p>computeHessian (line 36)
Error in C:\Program Files\MATLAB\R2013a\toolbox\optim\optim\barrier.p>barrier (line 300)
Error in fmincon (line 900) [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
You need to make a function that is defined such as
Then define your options as (You need to define it below the above