YALMIP constraint: Writing constraints for the first and last position

4 views (last 30 days)
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?

Answers (2)

John D'Errico
John D'Errico on 26 Nov 2017
Edited: John D'Errico on 26 Nov 2017
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 Comments
John D'Errico
John D'Errico on 26 Nov 2017
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 on 26 Nov 2017
Thank you for your help. I said I am "required" meaning that the assignment asks me to write one.

Sign in to comment.


Johan Löfberg
Johan Löfberg on 27 Nov 2017
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.

Products

Community Treasure Hunt

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

Start Hunting!