I want the following help in linear fashion:

  • I have a vector: P(n)=[1,2,3,4,5,...,n]
  • I have binary variables with length of P: y(1),y(2).....y(n). These variables, y(i) can only take 0 or 1.

A new vector Q(n) is needed, such that, if y(i) is 1, then the ith element in Q(n) should be 0. And in rest of the places, the P(n) should get repeated.

  • Example : if n=6, and y(1) and y(4) are 1 ,then Q(1) and Q(4), should be 0. The vector, Q will be as follows :

Q=[0 1 2 0 1 2].

  • Another example : if y(3) is 1, then Q should be as follows:

Q=[1 2 0 1 2 3].

Basically, beside the zeros on ith position, the vector P should repeat itself in non-zero positions of Q

Can you please help me formulating this problem?

More Parag Patil's questions See All
Similar questions and discussions