how do i find argmax?

조회 수: 456 (최근 30일)
shikhar
shikhar 2013년 5월 21일
편집: James Tursa 2021년 5월 18일
how do i find argmax of, say x=[1 2] without any user defined function?

채택된 답변

Walter Roberson
Walter Roberson 2013년 5월 21일
[argvalue, argmin] = min(x);
[argvalue, argmax] = max(x);
  댓글 수: 1
shikhar
shikhar 2013년 5월 21일
편집: shikhar 2013년 5월 21일
thanks a lot Mr.Roberson

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

추가 답변 (2개)

Lukasz Laszko
Lukasz Laszko 2019년 10월 28일
편집: Lukasz Laszko 2019년 10월 28일
I'm afraid the answer by Walter Roberson is not correct. According to docs the second returned value contains indices of the minimum/maximum values of x. So to find argmax, you need to call x(max_ind),
eg.
x=0.1:.01:4*pi;
[max_val max_ind]=max(cos(x))
argmax=x(max_ind)
-->> max_val=1
-->> argmax=2pi
-->> max_ind=619
  댓글 수: 3
James Tursa
James Tursa 2021년 5월 17일
편집: James Tursa 2021년 5월 18일
@Lukasz Laszko Argmax is defined as the elements of the domain (i.e., in this case the indexes) where the function (i.e., in this case the vector) obtains the maximum. See these definitions:
Walter's answer is correct according to these definitions.
Your use of cos(x) introduces another function inbetween that was not part of the original question. Did the original question have cos(x) that was subsequently edited out?
Walter Roberson
Walter Roberson 2021년 5월 18일
In the case a function that is effectively f(x(K)) and what you wanted was the x(K) then it would not be unreasonable to take
fx = f(x);
[~, argidx] = max(fx);
argmax = x(argidx);
This adds an extra level of indirection, but it would be a common one.

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


Konstantin
Konstantin 2018년 6월 12일
Great!!!!

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by