YALMIP constraint: Writing constraints for the first and last position
4 次查看(过去 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 中查找有关 Direct Search 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!