0
$\begingroup$

Hi So I have the following list:

data = {{3.73324*10^10 + 147881. s + 1. s^2, 1}, {3.73324*10^10 + 357017. s + 1. s^2, 1}}

(this is a short example, in this case the list has only two elements, but this is part of a big scheme of things)

I want to order the elements of this list based on a parameter Q

Q1 = Sqrt[CoefficientList[data[[1]][[1]], s][[1]]]/CoefficientList[data[[1]][[1]], s][[2]]
Q2 = Sqrt[CoefficientList[data[[2]][[1]], s][[1]]]/CoefficientList[data[[2]][[1]], s][[2]]

I want to order it by increasing values of Q so, in this case the elements should be swapped. What is the best way to do this in systematic way using sort? I have tried this but failed miserably, probably due to syntax:

Sort[FactorsDen, Sqrt[CoefficientList[#1[[2]][[1]], s][[1]]]/CoefficientList[#1[[2]][[1]], s][[2]]< Sqrt[CoefficientList[#2[[2]][[1]], s][[1]]]/CoefficientList[#2[[2]][[1]], s][[2]] &]

Any guess on how can I do this in an easy way? Thank you!

$\endgroup$

1 Answer 1

1
$\begingroup$
$Version

(* "13.2.1 for Mac OS X ARM (64-bit) (January 27, 2023)" *)

Clear["Global`*"]

metric[x_List] := 
 Module[{t = CoefficientList[x[[1]], s]}, Sqrt[t[[1]]]/t[[2]]]

data = {{3.73324*10^10 + 147881. s + 1. s^2, 
    1}, {3.73324*10^10 + 357017. s + 1. s^2, 1}};

SortBy[data, metric]

(* {{3.73324*10^10 + 357017. s + 1. s^2, 
  1}, {3.73324*10^10 + 147881. s + 1. s^2, 1}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.