フィルターのクリア

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 Center および File ExchangeNonlinear Optimization についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by