Minimizing a function with discrete variables
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Cam Salzberger
el 18 de Sept. de 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 comentarios
Alan Weiss
el 19 de Sept. de 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
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!