YALMIP constraint: Writing constraints for the first and last position
9 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (2 件)
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
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.
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Linear Least Squares についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!