# Select the highest root of the list

How can I select the highest root of the list? I was working to find only the root with the highest value.

{{B -> 0.622096}, {B -> 1.03445}, {B -> 48.6767}}


I want to apear only

{{B -> 48.6767}} or {B -> 48.6767}

• See Sort and Maximum. – David G. Stork Jun 25 '20 at 16:54

Perfect case for MaximalBy and the operator form of Lookup.

roots = {{B -> 0.622096}, {B -> 1.03445}, {B -> 48.6767}};

MaximalBy[roots, Lookup[B]]
(* {{B -> 48.6767}} *)

• Or MaximalBy[roots, Last] – Bob Hanlon Jun 26 '20 at 0:32
• In this case even MaximalBy[roots, Identity] works too. – Chip Hurst Jun 26 '20 at 0:52
• Or MaximalBy[roots, Values]. – chyanog Jun 26 '20 at 3:21
roots /. soln // Max


Works and uses core functions.

Try this:

expr = {{B -> 0.622096}, {B -> 1.03445}, {B -> 48.6767}};
B -> Max[Transpose[expr][] /. Rule[B, x_] -> x]
(*  B -> 48.6767  *)


Have fun!

I like the neat functionality of Ordering:

Extract[#,Ordering[#,-1]]&@roots


{B->48.6767}

If you prefer Cases:

Cases[#,List[Rule[b_,Max@Values@#]]]&@roots


{{B->48.6767}}

roots = {{B -> 0.622096}, {B -> 1.03445}, {B -> 48.6767}};

ClearAll[f1, f2, f3]

f1 = Merge[Max];
f2 = Last @* Sort;
f3 = #[[Ordering[#, -1]]] &;

f1 @ roots

<|B -> 48.6767|>


If you need a list:

Normal @ %

{B -> 48.6767}

f2  @ roots

{B -> 48.6767}

f3 @ roots

{{B -> 48.6767}}

roots = {{B -> 0.622096}, {B -> 1.03445}, {B -> 48.6767}};

TakeLargestBy[roots, #[[-1, -1]] &, 1]
(* {{B -> 48.6767}} *)