필터 지우기
필터 지우기

Create Hessian for fmincon from a large number of constraints

조회 수: 1 (최근 30일)
Vincent Porter
Vincent Porter 2018년 5월 24일
Is there a way to create a Hessian with a variable number of constraint equations?
gradc = jacobian(c,x).';
hessc1 = jacobian(gradc(:,1))
hessc2 = jacobian(gradc(:,2))
hessc3 = jacobian(gradc(:,3))
hessc4 = jacobian(gradc(:,4))
hessch1 = matlabFunction(hessc1)
hessch2 = matlabFunction(hessc2)
hessch3 = matlabFunction(hessc3)
hessch4 = matlabFunction(hessc4)
myhess = @(x,lambda)(hessfh(x) + ...
lambda.ineqnonlin(1)*hessc1h(x) + ...
lambda.ineqnonlin(2)*hessc2h(x) + ...
lambda.ineqnonlin(3)*hessc3h(x) + ...
lambda.ineqnonlin(4)*hessc4h(x));
Above works for a fixed number of constraints. But, I can't figure out if it is possible to create the myhess handle with a variable number of constraints.
I tried the below code which I used a string to create the code that would create the myhess handle and converted it into a function handle, but I don't think fmincon with take the myhess handle because I had to include an extra input @(x,lambda,hessch)
gradc = jacobian(c,x).';
hessc = [];
for i=1:size(c,2)
hessc = [hessc;{jacobian(gradc(:,i) ,x);}];
end
hessch = [];
for i=1:size(c,2)
hessch = [hessch;{matlabFunction(hessc{i}, 'vars',{x})}];
end
myhess = '@(x,lambda,hessch)(hessfh(x)+';
for i=1:length(hessch)
myhess = [myhess,'lambda.ineqnonlin(',num2str(i),')*hessch{',num2str(i),'}(x)+'];
end
myhess(end)=')';
myhess = str2func(myhess)
I am not very familiar with the syntax of creating function handles and any help would be greatly appreciated.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by