fmincon中不等式约束的粗麻布

时间:2018-11-16 09:40:55

标签: matlab nonlinear-optimization hessian-matrix

我正在尝试通过提供梯度矢量和Hessian矩阵来帮助fmincon更快收敛。我正在使用内点算法,并且意识到在这种情况下,我必须使用对另一个分配给我的OPTIOINS的HessFcn的函数的调用来提供Hessian。我只有不平等约束(C)。它是二次形式。

gbee_r_i,p_in,nel,nhp是已知的矩阵或变量。

我定义约束如下:

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

定义如下选项:

     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)

是HessFcn,定义如下。

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

运行程序后,显示此错误

使用@(x)hessinterior(x,lambda,gbee_r_i,p_in,nel,nhp)时出错 输入参数过多。

C:\ Program Files \ MATLAB \ R2013a \ toolbox \ optim \ optim \ private \ computeHessian.p> computeHessian中的错误 (第36行)

C:\ Program Files \ MATLAB \ R2013a \ toolbox \ optim \ optim \ barrier.p> barrier(第300行)中的错误

fmincon中的错误(第900行)     [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =     屏障(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn,...

1 个答案:

答案 0 :(得分:0)

你需要定义一个函数,例如

hess = @(x,lambda) cond5( x,lambda,gbee_r_i,p_in,nel,nh)

然后将您的选项定义为(您需要在上面定义它

 options = optimoptions(@fmincon,...
    'GradObj','on','GradConstr','on','Hessian','user-supplied',...
HessFcn',hess,'Display','iter','Algorithm','interior-point','maxFunEvals',20000000000000,'MaxIter',5000,'TolFun',1e-3);