フィルターのクリア

How to deal with discrete constraint fmincon

2 ビュー (過去 30 日間)
Saverio Borreli
Saverio Borreli 2021 年 2 月 9 日
回答済み: Aurele Turnes 2021 年 2 月 10 日
Hello! I'm writing the code for an optimization problem, and I'm having problem writing the equality constraints.
I have to write these constraints (discrete) and I don't know how to do it. I'm trying to write them into "Aeq", but I don't know how to handle this "sk+1" and "vk+1". Any ideas? Thank you

回答 (1 件)

Aurele Turnes
Aurele Turnes 2021 年 2 月 10 日
You can write the equality constraint matrix by keeping track of the indices, or you can use the new problem-based workflow to define these constraints more easily.
Start by defining your variables for say N = 10
N = 10;
% Some made-up data
tau = 0.1;
vlower = 0;
vupper = 1;
s0 = 1;
sF = 2;
v0 = 0.1;
vF = 0.8;
% Define variables
a = optimvar('a', N);
s = optimvar('s', N);
v = optimvar('v', N, 'LowerBound', vlower, 'UpperBound', vupper);
Then your constraints are simply:
conS = s(2:end) == s(1:end-1) + tau*v(1:end-1);
conV = v(2:end) == v(1:end-1) + tau*a(1:end-1);
conInitS = s(1) == s0;
conFinalS = s(end) == sF;
conInitV = v(1) == v0;
conFinalV = v(end) == vF;
Note that you could write the same constraints with a for-loop instead, but it is always more efficient to vectorize your code as above.
% conS = optimconstr(N-1,1);
% for i = 1:N-1;
% conS(i) = s(i+1) == s(i) + tau*v(i);
% end
Then, just create your optimproblem and populate Objective and Constraints.

カテゴリ

Help Center および File ExchangeProblem-Based Optimization Setup についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by