How can I do Exhaustive search in matlab?

조회 수: 11 (최근 30일)
Adi Nor
Adi Nor 2019년 11월 21일
댓글: QUANG LE 2020년 10월 6일
I have a function that depends on three variables x,y,z. I want to find the optimal values of these variables using exhaustive search that can maximize this function, subject to x+y+z<=1. How can I do this in Matlab?

채택된 답변

Walter Roberson
Walter Roberson 2019년 11월 21일
xvalues = [list all possible x values]
yvalues = [list all possible y values]
zvalues = [list all possible z values];
[X, Y, Z] = ndgrid(xvalues, yvalues, zvalues);
mask = X + Y + Z <=1;
x = X(mask);
y = Y(mask);
z = Z(mask);
f = x.^3 - log(y+z) + sin(z); %compute everything. %use appropriate function
[bestf, bestidx] = min(f); %or max(f) depending what you are trying to optimize
bestx = x(bestidx);
besty = y(bestidx);
bestz = z(bestidx);
  댓글 수: 5
Walter Roberson
Walter Roberson 2020년 10월 6일
mask = X + Y + Z <= maxP & X <= Y & Y <= Z;
QUANG LE
QUANG LE 2020년 10월 6일
Thanks so much, it works.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by