Minimizing a function with discrete variables
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Cam Salzberger
2017-9-18
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 个评论
Alan Weiss
2017-9-19
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!