Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'max element in matrix' topicStudent Support Forum > General > "max element in matrix"

< Previous CommentHelp | Reply To Comment | Reply To Topic
Author Comment/Response
Peter Pein
10/19/12 1:54pm

Hi Tatjana,

there is no need to use a nested loop.

The following gives you the maximal absolute value and a list of positions where these elements are located in the matrix:

In[7]:= A = RandomInteger[{-5, 5}, {4, 4}]
Out[7]= {{-5, 1, 3, -5},
{-2, 2, 5, 5},
{-5, 3, 2, -3},
{-4, 1, 0, 1}}

In[8]:= Block[{abs = Abs[A], max},
{max = Max[Flatten[abs]], Position[abs, max]}]
Out[8]= {5, {{1, 1}, {1, 4}, {2, 3}, {2, 4}, {3, 1}}}

Peter


URL: ,

Subject (listing for 'max element in matrix')
Author Date Posted
max element in matrix Tatjana 10/18/12 01:29am
Re: max element in matrix Bill Simpson 10/18/12 1:29pm
Re: max element in matrix Peter Pein 10/19/12 1:54pm
< Previous CommentHelp | Reply To Comment | Reply To Topic