Constraint with decision variable

6 ビュー (過去 30 日間)
Nana
Nana 2016 年 3 月 27 日
コメント済み: Walter Roberson 2016 年 3 月 29 日
How can I write a constraint for optimization which includes the decision variable (x)? The constraint is:
max (0, x(i-1) - P) <= x(i) <= min (C, x(i-1) + D)
  1 件のコメント
John D'Errico
John D'Errico 2016 年 3 月 27 日
編集済み: John D'Errico 2016 年 3 月 27 日
Don't all constraints for an optimization somehow involve the decision variables? Note that what you have written is actually more than one constraint. There are TWO inequalities there.

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

採用された回答

Walter Roberson
Walter Roberson 2016 年 3 月 28 日
You should use a couple of different kinds of constraints. But you are only constraining variable #i, so we have to initialize the constraints so the other variables are not affected
Nx = length(x);
%no equality constraints
Aeq = [];
beq = [];
%the constraint has to be for some _specific_ i
i = 13;
%now to construct x(i-1) - P <= x(i) and x(i) <= x(i-1) + D
A = zeros(2, Nx);
b = zeros(2, 1);
A(1, i-1) = 1; A(1, i) = -1; b(1) = P; % (1) * x(i-1) + (-1) * x(i) <= (P)
A(2, i-1) = -1; A(2, i) = 1; b(2) = D; % (-1) * x(i-1) + (1) * x(i) <= (D)
%lower bounds are -inf, upper bounds are +inf for all variables except #i
lb = -inf * ones(1, Nx);
ub = inf * ones(1, Nx);
%but for variable #i, the value cannot be less than 0 or more than C
lb(i) = 0;
ub(i) = C;
fmincon(@objective, x0, A, b, Aeq, beq, lb, ub)
Your constraints cannot be generalized to all of the variables because there is no x(0) to constrain x(1) against.
  2 件のコメント
Nana
Nana 2016 年 3 月 29 日
Hi Walter, thanks for your answer!
So basically, I need two columns of b?
Walter Roberson
Walter Roberson 2016 年 3 月 29 日
You need one entry in b for each of the separate constraints. You have two inequality constraints for each i, so two entries in b for each i. It does not matter whether you specify b as a row or as a column vector; a row vector will be transformed into a column vector internally.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by