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!