Max
Max
Max[ list ] returns the largest value in a list.
Usages
Max[ list ]
Max[ list ] returns the element of list with the largest numerical value. The element is returned as it is written in the list, for example Pi instead of 3.14....
| Example | in | out |
|---|---|---|
Pi is larger than 3 and Sqrt[3]. |
Max[ {3, Pi, Sqrt[3]} ] |
Pi |
| Negative numbers. | Max[ {-3, -1, -2} ] |
-1 |
| A fraction and a decimal number are compared by value. | Max[ {1/2, 0.4} ] |
1/2 |
| A list stored in a script variable. | L := {4, 9, 1} |
m = 9 |
Quantities with the same unit. In a script, use Simplify (see the note below). |
Simplify[ Max[ {Quantity[3,'m'], Quantity[5,'m']} ] ] |
Quantity[5, 'm'] |
Note
For quantities with a unit, Max is only calculated when the expression is simplified. In a script, Max[ {Quantity[3,'m'], Quantity[5,'m']} ] on its own stays unevaluated.
Details
- Equal values: if the largest value occurs more than once, the first one is returned.
- Elements without a numerical value: if any element has no numerical value (such as
x),Maxis left unevaluated:Max[ {2, x} ]staysMax[ {2, x} ].
| Invalid input | Result |
|---|---|
Max[ {} ] |
Left unevaluated. |
Max[ 5 ] |
Left unevaluated: the argument must be a list. |
Max[ 3, 5 ] |
Error: the number of arguments should be 1. Put the values in a list: Max[ {3, 5} ]. |