# How to set a constraint that the variable's first column is the minimum value in the remaining columns

Now I have a problem.There is a constraint that the variable’s first column is the minimum value in the remaining columns.

For example, I want to have a matrix X like this:
[1,2,3;
4,5,6;
7,8,9]

``````I try to set X's constraint as:
(-1)*x(:,1)<=0;
%        -x1<=0
repmat(x(:,1),1,3)-y(:,2:3)<=0;
%        x1-x23<=0
``````

But actually the X’s first column become zero.
The result as:
[0,2,3;
0,5,6;
0,8,9;]

This post was edited from the original to state `have <= the minimum value` rather than `have the minimum value`.

I don’t understand your question. Do you want
`X(:,1) <= min(X(:,2:end),[],2)`.
For each row, that constrains the first element to have <= the minimum value in that row (but ties are allowed).

Yes I just mean this. Thank you very much

I try your code but the problem is still here.
`X(:,1) <= min(X(:,2:end),[],2)`

Although the first column is smaller than the last columns， it becomes zero not the minimum value.

I try to set constraint as:
`X(:,1) = min(X(:,2:end),[],2)`
I wish that the variable’s first column is the minimum value in the remaining columns.

But there is error as:
The following cvx variable(s) have been cleared or overwritten:
y
This is often an indication that an equality constraint was
written with one equals ‘=’ instead of two ‘==’. The model
must be rewritten before cvx can proceed.

Whoops, my constraint constrained the first column to be <= the minimum of the other columns. (I wrote it incorrectly, but have now fixed it).

To do what you want, you can’t use a constraint (`==`), because that is a non-convex equality constraint. You can’t do assignment (’=’) to a variable; that is why you got the error message. So what you do is declare X to have one fewer columns, and use a new variable `X_min_per_row` to be the minimum of the columns of the now reduced dimension `X`. Assume your original X was m by n.

``````variable X(m,n-1)
expression X_min_per_row(m,1)
X_min_per_row = min(X,[],2);
``````

Make adjustments in the rest of your program as needed in light of this. if you want to create the original X, you can do so by concatenation. `X_original = [X_min_per_row X]`;

Because the expression `X_min_per_row` is not a scalar, it needs to be declared as an expression holder (array), as I have done, although `expression X_min_per_row(m)` could be used instead.

When I add `X_min_per_row` to object function,it warns me that `Illegal operation: {concave} + {convex}`.
My Partial objective function is to minimize `X_min_per_row`
`min` is concave. So to do what you want requires introduction of binary variables to “linearize” the non-convex use of `min.` Look at the last bullet of https://www.fico.com/fico-xpress-optimization/docs/latest/mipform/dhtml/chap2s1.html?scroll=ssecminval to see how. I leave you to work out the details for your program.