max
Finds the greatest of all real numbers in a container or in a sequence.
Syntax
-
max(a, b)
-
a
is a real number -
b
is a real number
-
-
max(X)
-
X
is a vector, matrix, list, set, or structure
-
-
max(expr, var, a, b)
-
expr
is an expression in one variablevar
-
var
is the variable inexpr
-
a
is the lower bound -
b
is the upper bound
-
Description
The greatest of two numbers
If a
and b
are real numbers, then max(a, b)
is the greatest of them.
Finding the greatest number in a container
-
If
v
is a real vector, thenmax(v)
is the greatest component ofv
. -
If
A
is a real matrix, thenmax(A)
is the greatest entry ofA
. -
If
L
is a non-empty list of real numbers, thenmax(L)
is the greatest of the elements ofL
. -
If
S
is a non-empty set of real numbers, thenmax(S)
is the greatest of the elements ofS
. -
If
S
is a structure containing real numbers, thenmax(S)
is the greatest of the numbers inS
.
Finding the greatest number in a sequence
max(expr, var, a, b)
is the greatest value of expr
as var
takes all integer values from a
to b
, inclusively. expr
must return a real value for every value of var
in [a, b] ∩ ℤ
. The number of elements in the sequence, b − a + 1
, must be at least 1
.
Examples
The greatest of two numbers
f ≔ x ↦ 5⋅max(x, 2)
custom function
Finding the greatest number in a container
max('(10/51, 49/256, 5/27, 6/29, 3/14, 24/121))
0.214285714286 (=3/14)
max(RandomVector(100))
0.991129796952
max(RandomIntMatrix(100, 100, 1000000))
999960
max(size(❨❨1, 2❩, ❨4, 1❩, ❨0, 1❩❩))
3
f ≔ n ↦ if(even(n), n/2, 3⋅n + 1);
n ≔ 27; L ≔ IteratedImages(f, n, 100); '(min(L), max(L))
23 9232
st ≔ n ↦ (c ≔ 0; k ≔ n; while(k ≠ 1, (k ≔ f(k); inc(c))); c);
max(SequenceVector(100) @ st)
118
max(compute(prime(succ(n)) − prime(n), n, 1, 1000000))
154
Finding the greatest number in a sequence
max(sin(k/2) + 5⋅cos(k/3) − sin(k/4), k, −10, 10)
5
f ≔ n ↦ if(even(n), n/2, 3⋅n + 1);
st ≔ n ↦ (c ≔ 0; k ≔ n; while(k ≠ 1, (k ≔ f(k); inc(c))); c);
max(st(n), n, 1, 100)
118