RankedMax
Details
- RankedMax yields a definite result if all its arguments are real numbers.
- If
is a list with the ordering
, then RankedMax[x,n] gives
and RankedMax[x,-n] gives
for
. - RankedMax[{x1,…,xm},1] is equivalent to Max[{x1,…,xm}]. »
- RankedMax[{x1,…,xm},-1] is equivalent to Min[{x1,…,xm}].
- RankedMax[{x1,…,xm},m] is equivalent to Min[{x1,…,xm}]. »
- RankedMax[{x1,…,xm},n] is equivalent to Quantile[{x1,…,xm},(m-n+1)/m]. »
Examples
open all close allBasic Examples (4)
The second largest of three numbers:
RankedMax[{12, 13, 11}, 2]The third largest of four numbers:
RankedMax[{Pi, Sqrt[2], E, 3}, 3]The second largest of a list of dates:
RandomDate[4]RankedMax[%, 2]Plot the second-largest function over a subset of the reals:
Plot[RankedMax[{(1/2), Cos[x], -(1/2)}, 2], {x, 0, 2π}]Scope (25)
Numerical Evaluation (7)
Evaluate the second largest of three numbers:
RankedMax[{12.6555, 33.5265, 25.65}, 2]The fourth largest—i.e the smallest—of four numbers:
RankedMax[{12, 13, 48.5, Pi}, 4]The second smallest of five numbers:
RankedMax[{2.5, E, 12, 15, 485}, -2]The fourth smallest of five numbers:
RankedMax[{2.5, E, 12, 15, 485}, -4]The fifth smallest—i.e. the largest—of five numbers:
RankedMax[{2.5, E, 12, 15, 485}, -5]N[RankedMax[{12, 24, 48.5, Pi}, 4], 50]N[RankedMax[{12, 52, E, Pi}, 4], 70]Evaluate efficiently at high precision:
RankedMax[{12, E, 99 / 3`100, Pi}, 4]//TimingRankedMax[{E, 5568586, 4856`10000000, Pi + E}, -4];//TimingRankedMax of WeightedData ignores the weights:
wd = WeightedData[{1, 2, 3, 4}, {1, 2, 1, 3}];RankedMax[wd, 2]RankedMax[wd["InputData"], 2]dates = WolframLanguageData[All, "DateIntroduced"];DateHistogram[dates]RankedMax[dates, 125]Compute the ranked max of times:
RandomTime[10]//SortRankedMax[%, 4]List of times with different time zone specifications:
{TimeObject[{12}, TimeZone -> 0], TimeObject[{12}, TimeZone -> 2], TimeObject[{12}, TimeZone -> "Asia/Tokyo"]}RankedMax[%, 2]Specific Values (4)
RankedMax[{∞, 5, ∞, -∞}, 2]RankedMax[{∞, 5, ∞, -∞}, -1]PiecewiseExpand[RankedMax[ {x, x + 1, y}, 3], -2 < x < 2, 3 < y < 4]Solve equations and inequalities:
Reduce[{RankedMax[{Sin[x], Cos[x], Sec[x]}, 2] > 0, 0 < x < 5}, x, Reals]Find a value of x for which RankedMax[{Sin[x],Cos[x],Exp[x]},2]1:
xval = x /. FindRoot[RankedMax[{Sin[x], Cos[x], Exp[x]}, 2] == 1, {x, 2}]Plot[RankedMax[{Sin[x], Cos[x], Exp[x]}, 2], {x, -5, 6}, Epilog -> Style[Point[{xval, RankedMax[{Sin[xval], Cos[xval], Exp[xval]}, 2]}], PointSize[Large], Red]]Visualization (3)
Plot RankedMax of several functions:
Plot[RankedMax[{Sin[x], Cos[x], Tan[x]}, 2], {x, 0, 2π}, PlotRange -> All]Plot RankedMax in three dimensions:
Plot3D[RankedMax[{x, y, x + y}, 2], {x, -3, 3}, {y, -3, 3}, ColorFunction -> "BlueGreenYellow"]Plot RankedMax of three functions in three dimensions:
Plot3D[RankedMax[{Tan[x], Tan[y], Tan[x + y]}, 2], {x, -3, 3}, {y, -3, 3}, ColorFunction -> "BlueGreenYellow"]Function Properties (8)
RankedMax is only defined for real-valued inputs:
RankedMax[{1, I, E}, 2]The range of RankedMax is real numbers:
FindInstance[Im[RankedMax[{x, y, z}, 2]] ≠ 0, {x, y, z}]Basic symbolic simplification is done automatically:
RankedMax[{x, y, z}, 1]RankedMax[{x, y, z}, 3]Multi-argument ranked RankedMax is generally not an analytic function:
FunctionAnalytic[RankedMax[ {1, x, x ^ 2}, 2], x]It will have singularities where the functions cross, but it will be continuous:
FunctionSingularities[RankedMax[ {1, x, x ^ 2}, 2], x]//Quiet//ReduceFunctionDiscontinuities[RankedMax[ {1, x, x ^ 2}, 2], x]//Quiet//Reduce
is neither nondecreasing nor nonincreasing:
FunctionMonotonicity[RankedMax[ {1, x, x ^ 2}, 2], x]FunctionInjective[RankedMax[ {1, x, x ^ 2}, 2], x]Plot[{RankedMax[ {1, x, x ^ 2}, 2], 1 / 2}, {x, -2, 2}]FunctionSurjective[RankedMax[ {1, x, x ^ 2}, 2], x]Plot[{RankedMax[ {1, x, x ^ 2}, 2], -1}, {x, -2, 2}]FunctionSign[RankedMax[ {1, x, x ^ 2}, 2], x]Series and Integration (3)
Series expansion of the second-largest function at the origin:
Series[RankedMax[{Exp[x], x ^ 2, Tanh[x]}, 2], {x, 0, 3}]Asymptotic expansion at Infinity:
Series[RankedMax[{1 / x, 1 / (x - 1), 1 / (x + 2)}, 3], {x, ∞, 3}]//FullSimplifyIntegrate expressions involving RankedMax:
Integrate[RankedMax[{x + 1, x, 1 + x^2}, 2], x]Integrate[Boole[RankedMax[{x + y, x - y, x y}, 2] < 2], {x, 0, 2}, {y, 0, 2}]Applications (7)
Plot the bivariate RankedMax functions:
Table[Plot3D[RankedMax[{x, y}, k], {x, -2, 2}, {y, -2, 2}, PlotLabel -> RankedMax[{x, y}, k]], {k, 2}]Plot the contours of bivariate and trivariate RankedMax functions:
Table[ContourPlot[RankedMax[{x, y}, k] == 0, {x, -2, 2}, {y, -2, 2}, PlotLabel -> RankedMax[{x, y}, k] == 0], {k, 2}]ParallelTable[ContourPlot3D[RankedMax[{x, y, z}, k] == 0, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, PlotLabel -> RankedMax[{x, y, z}, k] == 0], {k, 3}]RankedMax[{y1,…,yn,x},k] as a function of x:
data = Append[Range[1, 5] / 6, x]Table[Plot[RankedMax[data, k], {x, 0, 1}, Filling -> Axis, PlotLabel -> k, PlotRange -> {0, 1}], {k, 6}]Compute the expectation of the second smallest (median) variable:
Expectation[RankedMax[{x, y, z}, 2], {x, y, z}ProductDistribution[{ExponentialDistribution[λ], 3}]]Alternatively, use OrderDistribution:
Mean[OrderDistribution[{ExponentialDistribution[λ], 3}, 2]]Compute the probability of the second smallest variable being less than 1:
Probability[RankedMax[{x, y, z, w}, 2] < 1, {x, y, z, w}ProductDistribution[{ExponentialDistribution[λ], 4}]]Plot[%, {λ, 0, 5}]Find the height of the fourth tallest child in a class:
heights = Quantity[{134, 143, 131, 140, 145, 136, 131, 136, 143, 136, 133, 145, 147,
150, 150, 146, 137, 143, 132, 142, 145, 136, 144, 135, 141}, "Centimeters"];ListPlot[heights, Filling -> Axis, AxesLabel -> Automatic]r = RankedMax[heights, 4]n = Length[heights];
ListPlot[{heights, {{0, r}, {n, r}}}, Filling -> {1 -> 0}, Joined -> {False, True}, AxesLabel -> Automatic]Find the second-longest border of Germany:
data = CountryData["Germany", "BordersLengths"]RankedMax[Values[data], 2]Select[data, Last[#] == %&]Properties & Relations (6)
RankedMax[{x1,…,xm},1] is equivalent to Max[x1,…,xm]:
Table[RankedMax[Array[Subscript[x, #]&, {m}], 1] == Max[Array[Subscript[x, #]&, {m}]], {m, 4}]RankedMax[{x1,…,xm},m] is equivalent to Min[x1,…,xm]:
Table[RankedMax[Array[Subscript[x, #]&, {m}], m] == Min[Array[Subscript[x, #]&, {m}]], {m, 4}]RankedMax[{x1,…,xm},k] is equivalent to RankedMin[{x1,…,xm},m-k+1]:
With[{k = 2}, Table[RankedMax[Array[Subscript[x, #]&, {m}], k] == RankedMin[Array[Subscript[x, #]&, {m}], m - k + 1], {m, 2, 3}]]FullSimplify[PiecewiseExpand /@ %, _∈Reals]RankedMax[{x1,…,xm},n] is equivalent to Quantile[{x1,…,xm},(m-n+1)/m]:
data = RandomSample[Range[100], 10];Table[RankedMax[data, n] == Quantile[data, (10 - n + 1) / 10], {n, 10}]RankedMax[{x1,…,xm},n] is equivalent to Sort[{x1,…,xm},Greater]〚n〛:
data = RandomSample[Range[100], 10];Table[RankedMax[data, n] == Sort[data, Greater][[n]], {n, 10}]The equivalent Piecewise function has disjoint piecewise case domains:
PiecewiseDomains[HoldPattern[Piecewise[cases_, default_]]] :=
Module[{dl = Last /@ cases}, Append[dl, Not[Or@@dl]]]PiecewiseExpand[RankedMax[{x, y}, 2]]doms1 = PiecewiseDomains[%]Algebraically prove the piecewise case domains are disjoint:
Table[Resolve[ForAll[t, Exists[{x, y}, And@@ineqs]]], {ineqs, Subsets[doms1, {2}]}]Table[RegionPlot[Evaluate[doms1[[i]]], {x, -2, 2}, {y, -2, 2}, PlotStyle -> ColorData[95, i]], {i, 2}]doms2 = PiecewiseDomains[PiecewiseExpand[RankedMax[{x, y, z}, 2]]]Algebraically prove the piecewise case domains are pairwise disjoint:
Table[Resolve[ForAll[t, Exists[{x, y}, And@@ineqs]]], {ineqs, Subsets[doms2, {2}]}]Table[RegionPlot3D[Evaluate[doms2[[i]]], {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, PlotStyle -> ColorData[95, i], Lighting -> "Neutral", Mesh -> None, PlotPoints -> 35], {i, 3}]Neat Examples (2)
Two-dimensional sublevel sets:
Table[RegionPlot[RankedMax[{x, y}, 1] < t, {x, -2, 2}, {y, -2, 2}, PlotLabel -> RankedMax[{x, y}, 1] < t], {t, {-1, 0, 1}}]Table[RegionPlot[RankedMax[{x, y}, 2] < t, {x, -2, 2}, {y, -2, 2}, PlotLabel -> RankedMax[{x, y}, 2] < t], {t, {-1, 0, 1}}]Three-dimensional sublevel sets:
Table[RegionPlot3D[RankedMax[{x, y, z}, 1] < t, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, PlotLabel -> RankedMax[{x, y, z}, 1] < t], {t, {-1, 0, 1}}]Table[RegionPlot3D[RankedMax[{x, y, z}, 2] < t, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, PlotLabel -> RankedMax[{x, y, z}, 2] < t], {t, {-1, 0, 1}}]Table[RegionPlot3D[RankedMax[{x, y, z}, 3] < t, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, PlotLabel -> RankedMax[{x, y, z}, 3] < t], {t, {-1, 0, 1}}]Related Guides
Text
Wolfram Research (2010), RankedMax, Wolfram Language function, https://reference.wolfram.com/language/ref/RankedMax.html (updated 2024).
CMS
Wolfram Language. 2010. "RankedMax." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/RankedMax.html.
APA
Wolfram Language. (2010). RankedMax. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RankedMax.html
BibTeX
@misc{reference.wolfram_2026_rankedmax, author="Wolfram Research", title="{RankedMax}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/RankedMax.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_rankedmax, organization={Wolfram Research}, title={RankedMax}, year={2024}, url={https://reference.wolfram.com/language/ref/RankedMax.html}, note=[Accessed: 13-June-2026]}