フィルターのクリア

YALMIP constraint: Writing constraints for the first and last position

9 ビュー (過去 30 日間)
yuanb
yuanb 2017 年 11 月 26 日
回答済み: Johan Löfberg 2017 年 11 月 27 日
If I have:
y = [y_(1), ..., y_(N)]^T and z = [z_(1), ..., z_(N)]^T
I want to minimize a function V(y_(i), z_(i)) in which my constraints are
(y_(1), z_(1)) = (-2, 1) and
(y_(N), z_(N)) = (2, 1)
Consider N = 40.
I am required to write a constraint, so I would I have
y = sdpvar(1,N) and z = sdpvar(1,N)
now I just have to set (y1,z1) = (-2, 1) and (yN, zN) = (2,1). How can I write this in MATLAB?

回答 (2 件)

John D'Errico
John D'Errico 2017 年 11 月 26 日
編集済み: John D'Errico 2017 年 11 月 26 日
Don't. At least, don't write ANY constraints at all.
Just minimize the function for y(2:N-1) and z(2:n-1). Inside your objective function, create y and z as:
y = [-2, ..., 2]^T and z = [1, ..., 1]^T
Consider N as anything you want.
Be careful. If someone tells you to just set lower and upper bounds equal to each other, that often just results in numerical problems, unless the code explicitly states that this is a valid way to fix a variable at some level. In that case, the code will essentially remove those variables from the optimization for you.
  4 件のコメント
John D'Errico
John D'Errico 2017 年 11 月 26 日
No. You are not required to write a constraint. You are required to solve a problem with those variables held fixed. READ WHAT I WROTE IN MY ANSWER. Read it again.
If you insist on writing a constraint, then learn how to use linear equality constraints. Set up 4 equality constraints, one for each variable that you wish to fix.
yuanb
yuanb 2017 年 11 月 26 日
Thank you for your help. I said I am "required" meaning that the assignment asks me to write one.

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


Johan Löfberg
Johan Löfberg 2017 年 11 月 27 日
Model = [y(1) == -2, y(end) == 2, ...]
or simply assign those elements,
y(1) = -2;y(end)=2;...
YALMIP specific question should preferably be posted on the YALMIP google groups forum instead.

カテゴリ

Help Center および File ExchangeLinear Least Squares についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by