Arg max of a function

I have a doubt regarding finding arg max of a function m = x+y?
function m = equation(x,y)
k = x+y;
[max_value, max_ind] = max(k);
m = k(max_ind);
end
Thank you in advance

6 件のコメント

dpb
dpb 2020 年 11 月 21 日
Well, yes, you've tried to compare the LHS to the RHS via the equality "==" operator for some reason that is not at all clear although the immediate error is owing to the fact that neither variable referenced on the LHS is defined.
We don't know what you expect the function to do or return -- there's quite a lot wrong here besides beginning with the minor detail that equation is missspelled altho MATLAB doesn't care, it'll cause difficulty in remembering to use the misspellled version if continue.
But, you pass arguments x,y into the function but immediately overwrite them with local variables -- whassup w/ that?
There's really no way to proceed from this -- tell us what you're trying to do and include a sample of inputs and expected output(s) to help with the explanation.
Tina poddar
Tina poddar 2020 年 11 月 21 日
Thank you for your response
yeah i do see my error in putting the equality "==" operator i have fixed it .
So my main puropse is to implement these matrices value in the equation and find max values for which the equation gives maximum value. I was given the value of matrices x and y and asked to find the arg max of the equation x+y.
dpb
dpb 2020 年 11 月 22 日
But x+y is just a 2D array of constant values -- what do you think is some maximum or function? The question still makes no sense.
And what do you mean, precisely, by the phrase "arg max" that you keep using?
Tina poddar
Tina poddar 2020 年 11 月 22 日
Yes you are right it was my mistake and i have changed it.
Argmax is mainly that displays value which maxmize the function
Bruno Luong
Bruno Luong 2020 年 11 月 22 日
No, argmax is the argument at which the function (in your case the array result of plus) is maximized (hence the name ARGMAX)
You should return "max_ind" or "sub2ind(size(k),max_ind)" rather than k(max_ind) (which is btw equal to max_value).
Tina poddar
Tina poddar 2020 年 11 月 28 日
Thank you

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2020 年 11 月 21 日

1 投票

The operator + does not and cannot return two output arguments. Nor can its functional form, plus.
As a hint, take a look at the examples on the documentation page for the max function and see if you can adapt one of those to your needs.

1 件のコメント

Tina poddar
Tina poddar 2020 年 11 月 22 日
Thank you for response
However though i have made changes i am not able to get matrices of max values for which the function has max value that is arg max.
Can you please help

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

タグ

質問済み:

2020 年 11 月 21 日

コメント済み:

2020 年 11 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by