0
$\begingroup$

Prompted by my wrestling with this earlier question:

Changing the opacity of lines on a plot based on their value

I want to sort an association by the maximum value for each of the 3 members of the association over a specific range {x, 2/26, 1}.

assoc = <|"a:b" -> (2.888888888888889` x + 158.5679012345679` x^2 + 
       972.4261545496113` x^3 + 2782.574803223688` x^4 + 
       4689.153835062141` x^5 + 6158.852000788219` x^6 + 
       6193.345446598874` x^7 + 4759.487380195244` x^8 + 
       2828.1047688854555` x^9 + 1262.2623444432436` x^10 + 
       396.8075199523231` x^11 + 87.10349331793769` x^12 + 
       15.918345899682585` x^13 + 2.358273466619642` x^14)/(2 x + 
       142 x^2 + 994 x^3 + 3068 x^4 + 5440 x^5 + 7516 x^6 + 
       8061 x^7 + 6591 x^8 + 4215 x^9 + 2029 x^10 + 694 x^11 + 
       181 x^12 + 33 x^13 + 4 x^14), 
   "a:c" -> (1.9259259259259258` x + 154.85871056241427` x^2 + 
       1000.1077071584616` x^3 + 2910.6970670309593` x^4 + 
       4824.123299147454` x^5 + 6433.145771926378` x^6 + 
       6287.788973741406` x^7 + 4729.911569226189` x^8 + 
       2616.6377204567093` x^9 + 1072.3401991902406` x^10 + 
       300.41168315858073` x^11 + 66.12235989098919` x^12 + 
       9.795905169035438` x^13 + 1.179136733309821` x^14)/(2 x + 
       142 x^2 + 994 x^3 + 3068 x^4 + 5440 x^5 + 7516 x^6 + 
       8061 x^7 + 6591 x^8 + 4215 x^9 + 2029 x^10 + 694 x^11 + 
       181 x^12 + 33 x^13 + 4 x^14), 
   "a:e" -> (1.9259259259259258` x + 154.85871056241427` x^2 + 
       1177.8054158410812` x^3 + 3305.3824300345664` x^4 + 
       5174.381478951672` x^5 + 6568.697926267911` x^6 + 
       6234.040624961103` x^7 + 4385.353371436694` x^8 + 
       2365.2980972400514` x^9 + 900.9303208030539` x^10 + 
       255.51499204916647` x^11 + 41.96226685389699` x^12 + 
       6.122440730647148` x^13 + 1.179136733309821` x^14)/(2 x + 
       142 x^2 + 994 x^3 + 3068 x^4 + 5440 x^5 + 7516 x^6 + 
       8061 x^7 + 6591 x^8 + 4215 x^9 + 2029 x^10 + 694 x^11 + 
       181 x^12 + 33 x^13 + 4 x^14)|>; 

FindMaximum[#, {x, 2/26, 1}] & /@ assoc
Keys[Sort[%]]
assoc[#] & /@ %

Output

This seems to work, but have I missed something?

$\endgroup$

1 Answer 1

1
$\begingroup$

You could use SortBy instead:

SortBy[assoc, FindMaxValue[#, {x, 2/26,1}]&]

FindMaxValue::fmmp: Machine precision is insufficient to achieve the requested accuracy or precision.

<|"a:c" -> (1.92593 x + 154.859 x^2 + 1000.11 x^3 + 2910.7 x^4 + 4824.12 x^5 + 6433.15 x^6 + 6287.79 x^7 + 4729.91 x^8 + 2616.64 x^9 + 1072.34 x^10 + 300.412 x^11 + 66.1224 x^12 + 9.79591 x^13 + 1.17914 x^14)/(2 x + 142 x^2 + 994 x^3 + 3068 x^4 + 5440 x^5 + 7516 x^6 + 8061 x^7 + 6591 x^8 + 4215 x^9 + 2029 x^10 + 694 x^11 + 181 x^12 + 33 x^13 + 4 x^14), "a:e" -> (1.92593 x + 154.859 x^2 + 1177.81 x^3 + 3305.38 x^4 + 5174.38 x^5 + 6568.7 x^6 + 6234.04 x^7 + 4385.35 x^8 + 2365.3 x^9 + 900.93 x^10 + 255.515 x^11 + 41.9623 x^12 + 6.12244 x^13 + 1.17914 x^14)/(2 x + 142 x^2 + 994 x^3 + 3068 x^4 + 5440 x^5 + 7516 x^6 + 8061 x^7 + 6591 x^8 + 4215 x^9 + 2029 x^10 + 694 x^11 + 181 x^12 + 33 x^13 + 4 x^14), "a:b" -> (2.88889 x + 158.568 x^2 + 972.426 x^3 + 2782.57 x^4 + 4689.15 x^5 + 6158.85 x^6 + 6193.35 x^7 + 4759.49 x^8 + 2828.1 x^9 + 1262.26 x^10 + 396.808 x^11 + 87.1035 x^12 + 15.9183 x^13 + 2.35827 x^14)/(2 x + 142 x^2 + 994 x^3 + 3068 x^4 + 5440 x^5 + 7516 x^6 + 8061 x^7 + 6591 x^8 + 4215 x^9 + 2029 x^10 + 694 x^11 + 181 x^12 + 33 x^13 + 4 x^14)|>

$\endgroup$
1
  • $\begingroup$ Simpler, but does this give me anything different from what I get above? $\endgroup$
    – Jagra
    Commented Jun 21, 2019 at 20:50

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.