I need to create code that identifies the positions of all maximum elements of a list. I already know that if myList
contains only numbers, I can do
mList={0,1}
Position[myList,Max[myList]]
This will return, as expected, {{2}}
.
However my case is a bit more complicated because the list contains variables.
Here is an example to illustrate:
myList = {1, a};
Position[myList, Max[myList]]
This returns {}
.
I fully understand that this is because none of the elements in myList
matches the expression Max[1,a]
.
I've tried various variants of the following, to no avail:
PiecewiseExpand[Max[myList]]
Position[myList,%]
The first line returns, as expected: "1 if a<=1, a otherwise". But the second line returns {}
. (Again, I understand that this is because the list elements don't match the piecewise function.)
Is there a way to change this code so that I get the following desired result:
"1 if a <=1; 2 otherwise"
(That is: I want the output to be the unevaluated conditional statement.)