MATLAB: How to do the exhaustive search

discrete optimizationexhaustive searchglobal optimal

Dear all, I have a function with 7 variables, each variable belong to [0,20]. I want to search directly from the combination of these variables and find the global minimum value. Do you know is there any methods which are fit to this problem? Thank you in advance!

Best Answer

Perhaps your problem is one of integer values, 0 through 20 for each of your seven variables. If you cannot vectorize your function evaluations, then you are left with the prospect of evaluating the objective function 21^7 ~ 2e9 times, which would be quite time-consuming, but straightforward.
xbest = [0,0,0,0,0,0,0]
fmin = fun(xbest);
for i1 = 0:20
for i2 = 0:20
...
for i7 = 1:20
x = [i1,i2,i3,i4,i5,i6,i7]
f = fun(x)
if f < fmin
xbest = x
fmin = f
end
...
end
If you can vectorize your function evaluation, say x(5), x(6), and x(7), then you will have a much smaller set of indices to loop over. You would, in that example, need to evaluate 21^3 = 9261 function values at once and take the minimum. You would loop over that 21^4 = 194481 times.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation