Info

This question is closed. Reopen it to edit or answer.

how to write or constrains optimization

1 view (last 30 days)
mahmoud sayed
mahmoud sayed on 3 Feb 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
my problem in how to write the syntx of equality constrains in optimization for thatcase
x(1) =50 OR x(1) =20

Answers (1)

John D'Errico
John D'Errico on 3 Feb 2020
For which optimization tool? fmincon? You can't.
This essentially reduces to a discrete optimization problem. You can think of it as essentially a binary integer programming problem. Tools like fmincon cannot handle discrete variables. Period. fmincon assumes a continuously differentiable objective function of the parameters.
You can use the GA optimizer however. It allows discrete variables as an alternative.
And, of course, if you have only one variable that takes on just two possible levels, then you can make it even simpler - just run the optimization twice, setting x(1) in each case to 20 and then to 50. Take the better of the two solutions, and you have the optimal solution.

Community Treasure Hunt

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

Start Hunting!