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 Kommentare

dpb
dpb am 21 Nov. 2020
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 am 21 Nov. 2020
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 am 22 Nov. 2020
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 am 22 Nov. 2020
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 am 22 Nov. 2020
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 am 28 Nov. 2020
Thank you

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Steven Lord
Steven Lord am 21 Nov. 2020

1 Stimme

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 Kommentar

Tina poddar
Tina poddar am 22 Nov. 2020
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Tags

Gefragt:

am 21 Nov. 2020

Kommentiert:

am 28 Nov. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by