MaxI
MaxI
MaxI[ list ] returns the index of the largest value in a list.
Usages
MaxI[ list ]
MaxI[ list ] returns the position (starting at 1) of the element of list with the largest numerical value.
| Example | in | out |
|---|---|---|
The largest value is at position 1. |
MaxI[ {3, 2, 1} ] |
1 |
Sqrt[7] is the largest value. |
MaxI[ {Sqrt[3], Sqrt[5], Sqrt[7]} ] |
3 |
| Use the index to look up the element. | L := {40, 10, 30} |
i = 1v = 40 |
Details
- Equal values: if the largest value occurs more than once, the first position is returned:
MaxI[ {5, 2, 5} ]returns1. - Elements without a numerical value: if any element has no numerical value (such as
x),MaxIis left unevaluated:MaxI[ {2, x} ]staysMaxI[ {2, x} ].
| Invalid input | Result |
|---|---|
MaxI[ {} ] |
0, which is not a valid position. |
MaxI[ 5 ] |
5: an argument that is not a list is returned unchanged. |
MaxI[ 3, 5 ] |
Error: the number of arguments should be 1 |
Warning
MaxI only works correctly if the largest value is greater than 0. If all values are 0 or negative, MaxI returns 0: MaxI[ {-3, -1, -2} ] returns 0 instead of 2. In that case, use MinI on the negated values, for example MinI[ Map[x -> CalcTimes[-1, x], L] ].