When using fmincon can I have a variable be constrainted by either a range OR zero?
Show older comments
Essentially could I have a variable be between 5 and 20 OR be 0. The way I currently have it when I apply the range 5 to 20 I lose the ability for the solution to work at 0. Is there another optimization I can use for this? Thanks.
1 Comment
Crazy Cool
on 25 Jul 2017
Answers (1)
Titus Edelhofer
on 25 Jul 2017
1 vote
Hi,
programmatically: yes, you can always formulate something like this as a non linear constraint. But the optimizer (and the theory behind) doesn't like the variable to jump. Let's say you have a value of 5. The optimizer (somewhat simplified:) ) looks in the neighborhood of the current point for a better solution, but will never do the jump to the zero.
Is your problem non linear so that you have to use fmincon? If it was linear, then intlinprog would be suitable to handle such cases through adding additional variables (and using integer variables).
Titus
5 Comments
Crazy Cool
on 25 Jul 2017
Crazy Cool
on 25 Jul 2017
Steven Lord
on 25 Jul 2017
How many variables do you have and how many of them need to have this 0 OR in-a-range behavior? If the number of variables that you need to constrain this way is small, solve the problem with the first set to 0 and the rest allowed to vary normally, then the second set to 0 and the rest varying normally, then the first two set to 0 and the rest varying normally, etc. Once you've solved those subproblems, take the one with the best result.
Crazy Cool
on 25 Jul 2017
Edited: Crazy Cool
on 25 Jul 2017
Crazy Cool
on 25 Jul 2017
Categories
Find more on Choose a Solver 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!