max - Maple Programming Help

max

find the maximum of numbers

min

find the minimum of numbers

 Calling Sequence max(x1, x2, ...) min(x1, x2, ...) max[defined](x1, x2, ...) min[defined](x1, x2, ...) max[index](C) min[index](C) max[index,defined](C) min[index,defined](C)

Parameters

 x1, x2, ... - any expressions C - list, set, Matrix, Array or Vector

Description

 • The functions max and min return the maximum or minimum, respectively, of one or more arguments.
 • Most often the arguments are of type numeric, being integers, rationals, or floats.  However, the functionality is more general, allowing any type of argument for which an unevaluated function call may be returned.  When given a list or rtable-based Array as an argument, the maximum or minimum element contained in the list or Array will be returned.
 • In most cases, a call to max or min containing an undefined value will produce undefined as its result.
 • A call to max where one of the arguments is positive infinity will produce positive infinity as a result. Likewise, a call min containing negative infinity will produce negative infinity as a result. 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](...).
 • 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 will be 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.

Examples

The following examples locate the maximum or minimum of numeric or constant values.

 > $\mathrm{min}\left(1\right)$
 ${1}$ (1)
 > $\mathrm{max}\left(\frac{3}{2},1.49\right)$
 $\frac{{3}}{{2}}$ (2)
 > $\mathrm{max}\left(\frac{3}{5},\mathrm{ln}\left(2\right),\frac{9}{13},-\mathrm{∞}\right)$
 ${\mathrm{ln}}{}\left({2}\right)$ (3)
 > $a≔24:$
 > $b≔-3:$
 > $\mathrm{max}\left(a,b\right)$
 ${24}$ (4)

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

 > $\mathrm{min}\left(\frac{3}{2},1.49,f\left(x\right)\right)$
 ${\mathrm{min}}{}\left({1.49}{,}{f}{}\left({x}\right)\right)$ (5)

Use the defined option to determine the maximum or minimum ignoring all undefined values (returns the max/min of all defined values).

 > $\mathrm{max}\left(\frac{3}{2},1.49,\mathrm{undefined},2.5\right)$
 ${\mathrm{undefined}}$ (6)
 > $\mathrm{max}[\mathrm{defined}]\left(\frac{3}{2},1.49,\mathrm{undefined},2.5\right)$
 ${2.5}$ (7)
 > $\mathrm{min}[\mathrm{defined}]\left(\mathrm{undefined},8,-3446\right)$
 ${-}{3446}$ (8)

Note that infinity is known to be a maximum even in the presence of undefined,

 > $\mathrm{max}\left(\frac{3}{2},1.49,\mathrm{undefined},\mathrm{∞}\right)$
 ${\mathrm{∞}}$ (9)

Some algebraic combinations can be reduced

 > $\mathrm{max}\left(x+1,x+2,y\right)$
 ${\mathrm{max}}{}\left({y}{,}{x}{+}{2}\right)$ (10)

The minimum and maximum of no arguments are, as expected, positive and negative infinity, respectively.

 > $\mathrm{min}\left(\right)$
 ${\mathrm{∞}}$ (11)
 > $\mathrm{max}\left(\right)$
 ${-}{\mathrm{∞}}$ (12)

unevaluated max/min expressions containing polynomials can be converted to piecewise functions

 > $\mathrm{convert}\left(\mathrm{max}\left({x}^{2}-2,x+3\right),\mathrm{piecewise}\right)$
 ${{}\begin{array}{cc}{{x}}^{{2}}{-}{2}& {x}{\le }\frac{{1}}{{2}}{-}\frac{{1}}{{2}}{}\sqrt{{21}}\\ {x}{+}{3}& {x}{\le }\frac{{1}}{{2}}{+}\frac{{1}}{{2}}{}\sqrt{{21}}\\ {{x}}^{{2}}{-}{2}& \frac{{1}}{{2}}{+}\frac{{1}}{{2}}{}\sqrt{{21}}{<}{x}\end{array}$ (13)
 > $\mathrm{convert}\left(\mathrm{min}\left({x}^{3}+8,x+8\right),\mathrm{piecewise}\right)$
 ${{}\begin{array}{cc}{{x}}^{{3}}{+}{8}& {x}{\le }{-}{1}\\ {x}{+}{8}& {x}{\le }{0}\\ {{x}}^{{3}}{+}{8}& {x}{\le }{1}\\ {x}{+}{8}& {1}{<}{x}\end{array}$ (14)

max and min will search for values inside a container such as a list, set, Matrix, Vector, or Array

 > $\mathrm{max}\left(\left[1,2,3,4\right],⟨5,6,7⟩\right)$
 ${7}$ (15)

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≔\left[11,12,13,14\right]$
 ${L}{≔}\left[{11}{,}{12}{,}{13}{,}{14}\right]$ (16)
 > $\mathrm{ind}≔\mathrm{max}[\mathrm{index}]\left(L\right)$
 ${\mathrm{ind}}{≔}{4}$ (17)
 > ${L}_{\mathrm{ind}}$
 ${14}$ (18)

Two-dimensional indexes 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≔\mathrm{Matrix}\left(\left[\left[11,12\right],\left[21,22\right]\right]\right)$
 ${M}{≔}\left[\begin{array}{rr}{11}& {12}\\ {21}& {22}\end{array}\right]$ (19)
 > $\mathrm{ind}≔\mathrm{max}[\mathrm{index}]\left(M\right)$
 ${\mathrm{ind}}{≔}{2}{,}{2}$ (20)
 > ${M}_{\mathrm{ind}}$
 ${22}$ (21)

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.

 > $M≔\mathrm{Matrix}\left(\left[\left[11,12\right],\left[21,22\right]\right]\right)$
 ${M}{≔}\left[\begin{array}{rr}{11}& {12}\\ {21}& {22}\end{array}\right]$ (22)
 > ${M}_{1}≔\left[44,55,66\right]$
 ${{M}}_{{1}}{≔}\left[{44}{,}{55}{,}{66}\right]$ (23)
 > $M$
 $\left[\begin{array}{cc}\left[{44}{,}{55}{,}{66}\right]& \left[{44}{,}{55}{,}{66}\right]\\ {21}& {22}\end{array}\right]$ (24)

An error is expected here:

 > $\mathrm{ind}≔\mathrm{max}[\mathrm{index}]\left(M\right)$

the options index and defined can be used together to search for an extreme value in a container while ignoring undefined

 > $V≔⟨-4,77,\mathrm{undefined},-\mathrm{∞}⟩$
 ${V}{≔}\left[\begin{array}{c}{-}{4}\\ {77}\\ {\mathrm{undefined}}\\ {-}{\mathrm{∞}}\end{array}\right]$ (25)
 > $\mathrm{ind}≔\mathrm{max}['\mathrm{index}','\mathrm{defined}']\left(V\right)$
 ${\mathrm{ind}}{≔}{2}$ (26)
 > ${V}_{\mathrm{ind}}$
 ${77}$ (27)

Compatibility

 • The max and min commands were updated in Maple 2015.
 • The C parameter was introduced in Maple 2015.