Minimizing a function with discrete variables
6 views (last 30 days)
Show older comments
Hi,
How can I minimize the sum f(x1,x2) = x1+x2 where both x1 and x2 are discrete and can only assume values from a set of pre-defined values?
Thank you for the help
0 Comments
Answers (1)
Cam Salzberger
on 18 Sep 2017
Hello Koel,
If your set of possible values is sufficiently small, and you're only dealing with a few variables, it probably is easiest to just meshgrid or ndgrid the values, compute the function on all possible combinations, and find the global minimum.
If your function takes a long time to compute, there are too many possible values, or you're dealing with too many variables to make that feasible, probably best to look into integer programming. If your set of possible values are just integer values, you're home free with intlinprog.
If not, your function becomes essentially non-linear, as the function will use the integers to index into the set of possible values. You could try out some global optimization algorithms if you have access to that. Or you could check out some File Exchange offerings like this one. I can't speak for the quality or effectiveness of File Exchange submissions though.
-Cam
2 Comments
Alan Weiss
on 19 Sep 2017
Oh, I thought that you were given a set of [x1,x2] values. If you are given values for x1 and x2 separately, then because your f is monotone in both arguments, you just need to minimize x1 and x2 separately.
solution = min(a) + min(b)
where a and b are the arrays of x1 and x2 values separately.
But this is so simple that I think I am still missing something.
Alan Weiss
MATLAB mathematical toolbox documentation
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!