max
find the maximum of numbers
min
find the minimum of numbers
Calling Sequence
Parameters
Description
Thread Safety
Examples
Compatibility
max(x1, x2, ...)
min(x1, x2, ...)
max[defined](x1, x2, ...)
min[defined](x1, x2, ...)
max[nodefault](x1, x2, ...)
min[nodefault](x1, x2, ...)
max[defined,nodefault](x1, x2, ...)
min[defined,nodefault](x1, x2, ...)
max[index](C)
min[index](C)
max[index,defined](C)
min[index,defined](C)
x1, x2, ...
-
any expressions
C
list, set, Matrix, Array, or Vector
The functions max and min return the maximum and minimum, respectively, of one or more arguments.
Most often the arguments are of type numeric: integers, rationals, or floating-point numbers. However, the functionality is more general, as described in this section.
When given a list, set, Array, Vector, or Matrix (a container) as an argument, the maximum or minimum element in the container is returned. Multiple container arguments will result in the maximum of the maximums or minimum of the minimums.
Each value processed by max and min is recognized as falling into one of four categories: algebraic, numeric, Boolean, or string.
The values can be a mix of algebraic values and one of the numeric, Boolean, or string categories of values. If there are values of more than one of these three categories, an exception is raised.
If the values consist solely of numeric, Boolean, or string values, the maximum or minimum value is returned.
If any values are algebraic and a maximum or minimum cannot be determined, an unevaluated call to max or min is returned, with arguments consisting of the algebraic values, and one argument consisting of the maximum or minimum of the non-algebraic values if any were present.
In most cases, a call to max or min containing an undefined value returns undefined.
A call to max where one of the arguments is positive infinity and all the others are algebraic or numeric returns positive infinity. Likewise, a call to min containing negative infinity returns negative infinity. This is true even if one of the other arguments to max or min is undefined.
To ignore undefined values when computing the maximum or minimum, use the optional index defined. That is, max[defined](...).
By default, a call to max or min with no arguments or with only empty container arguments returns negative or positive infinity, respectively. If called with the index nodefault, the result is NULL instead.
The functions max[index] and min[index] return the index of the maximum or minimum element in the container C.
Only one argument can be supplied when using the [index] variations. The mandate for this option is that C[ max[index](C) ] give the maximal element. That mandate cannot be fulfilled when C is a sequence, or when C is a container that has other containers inside (such as a list of vectors); an error is raised in these situations.
These routines use evalr to try to resolve the relevant inequalities. Since evalr uses the current setting of Digits for its computations, it may help to increase Digits if either max(...) or min(...) returns unevaluated.
The maximum and minimum of polynomials can be converted to a piecewise function.
The max and min commands are thread-safe as of Maple 15.
For more information on thread safety, see index/threadsafe.
The following examples locate the maximum or minimum of numeric or constant values.
min⁡1
1
max⁡32,1.49
32
max⁡35,ln⁡2,913,−∞
ln⁡2
a≔24:
b≔−3:
max⁡a,b
24
When an unknown is present, the max/min of the known values will be reduced, and the whole expression will be returned as an unevaluated function call, which can be symbolically manipulated or further evaluated later.
min⁡32,1.49,f⁡x
min⁡1.49,f⁡x
Use the defined option to determine the maximum or minimum ignoring all undefined values (returns the max/min of all defined values).
max⁡32,1.49,undefined,2.5
undefined
maxdefined⁡32,1.49,undefined,2.5
2.5
mindefined⁡undefined,8,−3446
−3446
Note that infinity is known to be a maximum even in the presence of undefined.
max⁡32,1.49,undefined,∞
∞
Some algebraic combinations can be reduced.
max⁡x+1,x+2,y
max⁡y,x+2
max and min can work with Boolean values:
max⁡true,false
true
max⁡true,FAIL
FAIL
min⁡true,FAIL
The minimum and maximum of no arguments are, as expected, positive and negative infinity, respectively.
min⁡
max⁡
−∞
To return NULL instead, use the index nodefault.
maxnodefault⁡
Unevaluated max/min expressions containing polynomials can be converted to piecewise functions.
convert⁡max⁡x2−2,x+3,piecewise
x2−2x≤12−212x+3x≤12+212x2−212+212<x
convert⁡min⁡x3+8,x+8,piecewise
x3+8x≤−1x+8x≤0x3+8x≤1x+81<x
max and min will search for values inside containers such as a list, set, Matrix, Vector, or Array.
max⁡1,2,3,4,5,6,7
7
Use the index option to determine the location of the maximum or minimum value. Only one argument can be used when asking for the index.
L≔11,12,13,14
ind≔maxindex⁡L
ind≔4
Lind
14
Two-dimensional indices are returned as a sequence and can be used to directly index the maximum or minimum value. If multiple extreme values occur, only one index will be returned.
M≔Matrix⁡11,12,21,22
M≔11122122
ind≔maxindex⁡M
ind≔2,2
Mind
22
max can find the maximum in a list of Arrays (or Array of lists, or general data container inside a data container). However, max[index] will raise an error because there is no simple index that can reference the element.
M1≔44,55,66
M
44,55,6644,55,662122
An error is expected here:
Error, max value cannot be reached via a one-level index
The options index and defined can be used together to search for an extreme value in a container while ignoring undefined.
V≔−4,77,undefined,−∞
V≔−477undefined−∞
ind≔maxindex,defined⁡V
ind≔2
Vind
77
The C parameter was introduced in Maple 2015.
For more information on Maple 2015 changes, see Updates in Maple 2015.
The nodefault option was introduced in Maple 2017.
For more information on Maple 2017 changes, see Updates in Maple 2017.
The max and min commands were updated in Maple 2021.
See Also
convert/piecewise
evalr
extrema
initialfunctions
maximize
minimize
Download Help Document