max

Maximum of numbers

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

max(x1, x2, , …)
max({x1, x2, …})
max([x1, x2, …])
max(A)

Description

max(x1, x2, ...) returns the maximum of the numbers x1, x2, ….

If the arguments of max are either integers, rational numbers, or floating-point numbers, then max returns the numerical maximum of these arguments.

Exact numerical expressions such as PI + sqrt(2) etc. are internally converted to floating-point intervals using the current value of DIGITS. After comparison, the exact expression is restored in the return value. If the current value of DIGITS does not suffice to determine the maximum of several expressions, a symbolic call of max is returned. Cf. Example 2.

The call max() is illegal and leads to an error message. If there is only one argument x1, then max evaluates x1 and returns it. Cf. Example 3.

If one of the arguments is infinity, then max returns infinity. If an argument is -infinity, then it is removed from the argument list. Cf. Example 4.

max returns an error when one of its arguments is a complex number or a floating point interval with non-zero imaginary part. Cf. Example 3.

If one of the arguments is not a number, then a symbolic max call with the maximum of the numerical arguments and the remaining evaluated arguments may be returned. Cf. Example 1.

Nested max calls with symbolic arguments are rewritten as a single max call, i.e., they are flattened. Cf. Example 5.

max reacts to a very limited set of properties of identifiers set via assume. Use simplify to handle more general assumptions. Cf. Example 5.

Environment Interactions

When called with exact numerical expressions such as PI, sqrt(2) etc., the function is sensitive to the environment variable DIGITS, which determines the numerical working precision.

Examples

Example 1

max computes the maximum of integers, rational numbers, and floating-point values:

max(-3/2, 7, 1.4)

Floating point intervals are interpreted as "any number within this range" and may thus cause symbolic max calls to be returned:

max(2...3 union 6...7, 4)

max(2...3, 6...7, 4)

max(2...3, PI)

If the argument list contains symbolic expressions, then a symbolic max call may be returned:

delete b:
max(-4, b + 2, 1, 3)

In the following two examples, max is able to determine the maximum despite getting symbolic arguments (contrast this with <):

max(sqrt(2), 1)

assume(x > 0):
max(exp(x), exp(-x))

Example 2

The following rational number pi approximates π to about 20 decimal places:

pi := 314159265358979323846/10^20:

With the default value DIGITS = 10, the function max cannot distinguish between PI and pi via floating-point approximations:

max(pi, PI)

With an increased value of DIGITS, the floating-point interval approximation of PI considered by max allows to decide that PI is larger than pi:

DIGITS := 20:
max(pi, PI)

delete pi, DIGITS:

Example 3

max with one argument returns the evaluated argument:

delete a:
max(a), max(sin(2*PI)), max(2)

Complex numbers lead to an error message:

max(0, 1, I)
Error: The argument is invalid. [max]

Example 4

infinity is always the maximum of arbitrary arguments:

delete x:
max(100000000000, infinity, x)

-infinity is removed from the argument list:

max(100000000000, -infinity, x)

Example 5

max reacts only to very few properties of identifiers set via assume:

delete a, b, c:
assume(a > 0 and b > a and c > b):
max(a, max(b, c), 0)

An application of simplify yields the desired result:

simplify(%)

Parameters

x1, x2, …

Arbitrary MuPAD® objects

A

An array of domain type DOM_HFARRAY with real entries

Return Values

One of the arguments, a floating-point number, or a symbolic max call.

Overloaded By

See Also

MuPAD Functions

Was this topic helpful?