MATLAB: Fmincon constraining some variables and not others

constraintfmincon

Hello,
I am trying to optimise a function depending on 6 optimisable variables using fmincon(). Some of the variables should be under inequality linear constrains, while others shouldn't have any constrain at all. Is there the possibility to enforce this with fmincon()?
I know that linear inequality constrains should be enforced by defining the system A · x ≤ b, but this forces me to impose a constrain over every element in x. Setting A(i,i) and b(i) as 0 seems a waste of CPU since fmincon() will probably keep using a constrain that actually is not.
One could think to define (A,b) and make their indices empty where no constrain should be, but of course this just concatenates A and b if they are vectors or is an error if A is a matrix.
Thank you for your answers.

Best Answer

Setting A(i,i) and b(i) as 0 seems a waste of CPU since fmincon() will probably keep using a constrain that actually is not.
In theory, you can make A of type sparse, so that multiplications A(i,j)*x(j) for A(i,j)=0 will not be done explicitly. However, for such a small 6-variable problem, it doesn't make much sense. It is unlikely that these computations will consume noticeable additional CPU time.