# When using fmincon can I have a variable be constrainted by either a range OR zero?

1 vue (au cours des 30 derniers jours)
Crazy Cool le 25 Juil 2017
Commenté : Crazy Cool le 25 Juil 2017
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 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Crazy Cool le 25 Juil 2017
An additional comment: I have a series of variables and need to be over 1 and under 20 but the can not be chosen to use and thus also could be 0, how could I do this?

Connectez-vous pour commenter.

### Réponses (1)

Titus Edelhofer le 25 Juil 2017
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 commentairesAfficher 3 commentaires plus anciensMasquer 3 commentaires plus anciens
Crazy Cool le 25 Juil 2017
Modifié(e) : Crazy Cool le 25 Juil 2017
Yeah I need this to work to a scalable amount of variables. Is there a way I can manipulate the nonlin constraint side to make this work? Each variable comes in with a range AND they can all also be set to 0. A few have just 1 value they can be other than 0.
Crazy Cool le 25 Juil 2017
Do you have any ideas on how I might be able to do this?

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Choose a Solver dans Help Center et File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by