how do i find argmax?

458 visualizaciones (últimos 30 días)
shikhar
shikhar el 21 de Mayo de 2013
Editada: James Tursa el 18 de Mayo de 2021
how do i find argmax of, say x=[1 2] without any user defined function?

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Mayo de 2013
[argvalue, argmin] = min(x);
[argvalue, argmax] = max(x);
  1 comentario
shikhar
shikhar el 21 de Mayo de 2013
Editada: shikhar el 21 de Mayo de 2013
thanks a lot Mr.Roberson

Iniciar sesión para comentar.

Más respuestas (2)

Lukasz Laszko
Lukasz Laszko el 28 de Oct. de 2019
Editada: Lukasz Laszko el 28 de Oct. de 2019
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 comentarios
James Tursa
James Tursa el 17 de Mayo de 2021
Editada: James Tursa el 18 de Mayo de 2021
@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 el 18 de Mayo de 2021
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.

Iniciar sesión para comentar.


Konstantin
Konstantin el 12 de Jun. de 2018
Great!!!!

Categorías

Más información sobre GPU Computing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by