fmincon constraining some variables and not others
8 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Matt J
on 1 Dec 2020
Edited: Matt J
on 1 Dec 2020
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.
More Answers (1)
Ameer Hamza
on 1 Dec 2020
Edited: Ameer Hamza
on 1 Dec 2020
"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."
Why do you think so?
Conside the constraint
You will define it like this
A = [1 0 0 0 1 0];
B = 2;
This does not impose any constraint on x2, x3, x4, and x6.
3 Comments
Matt J
on 1 Dec 2020
Simple bounds like x1<=3, x5<=68 should not be expressed using the A,b matrices. You should use the lb, ub arguments for those. In any case, recent versions of Matlab will pre-analyze your A,b matrices to see if they contain any simple bounds and rewrite your constraints automatically.
See Also
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!