# Expressing a Constraint in an optimization problem

If I have a vector of M "continuous" decision variables (say it is called x) , and if I want a constraint to express that only one of them is allowed to have a nonzero value (i.e. no more than one variable can be nonzero). How can I express such constraint?

I am not sure if this is going to work as you want -because there is very little information in your question-. But you can introduce a vector of binary variables $$w\in\{0,1\}^n$$, then add $$x_i = w_i\times b_i$$ -where $$b_i$$ is a real number-, and $$\sum_i w_i = 1$$ (summation in the classical sense not XOR, e.g. $$1+1=2$$) as constraints. The second condition enforces that only one $$w_i$$ is $$1$$ (say $$i=j$$) and the first condition enforces that only $$x_j$$ is nonzero and it is equal to $$b_j$$.