Imposing Constraint in FMINCON optimization problem.

1 回表示 (過去 30 日間)
Luca Lange
Luca Lange 2022 年 5 月 17 日
コメント済み: Luca Lange 2022 年 5 月 17 日
Dear all,
I am trying to implement a constraint, saying that the sum of some variables in the problem should be equal to a certain fixed value (1 in this example). I am not quite familiar with the problem structure in these problems, and could not find any examples in the Matlab documentation. The code below shows the set up I have right now:
x0 = [zeros(1,N_plies) ones(1,N_plies)*t/N_plies];
lb = [-ones(1,N_plies)*90 zeros(1,N_plies)];
ub = [ones(1,N_plies)*90 ones(1,N_plies)*t];
c = @(x) sum(x(end/2+1:end)) == 1; %this does not work as handle for 'nonlcon'
opts = optimoptions(@fmincon,'Algorithm','sqp');
problem = createOptimProblem('fmincon','objective',...
@(x) ABDobjective(x),'x0',x0,'lb',lb,'ub',ub,'nonlcon',c,'options',opts);
Does anybody know of a way to make this work, or where there might be more information on how to set up this sort of structure?
Thanks,
Luca

採用された回答

Matt J
Matt J 2022 年 5 月 17 日
x0 = zeros(1,N_plies);
lb = [-ones(1,N_plies)*90 zeros(1,N_plies)];
ub = [ones(1,N_plies)*90 ones(1,N_plies)*t];
Aeq=zeros(size(lb)); Aeq(end/2+1:end) = 1; %the sum constraint
beq=1;
opts = optimoptions(@fmincon,'Algorithm','sqp');
problem = createOptimProblem('fmincon','objective',...
@(x) ABDobjective(x),'x0',x0,'lb',lb,'ub',ub,'Aeq',Aeq,'beq',beq,'options',opts);
  1 件のコメント
Luca Lange
Luca Lange 2022 年 5 月 17 日
Perfect! Did not know about this... (https://nl.mathworks.com/help/optim/ug/linprog.html)

サインインしてコメントする。

その他の回答 (1 件)

Torsten
Torsten 2022 年 5 月 17 日
Aeq = [zeros(1,N_plies),ones(1,N_plies)];
beq = 1.0;

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by