3
$\begingroup$

Suppose I have the following polynomials in an association i.e. <|...|>, they are:

x1 = <|"pol1" -> (354.070 x + 1139.013 x^2 + 2301.827 x^3 + 
       3772.240 x^4)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4), 
   "pol2" -> (353.073 x + 1154.929 x^2 + 2345.483 x^3 + 
       3829.635 x^4)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4)|>;

My problem is to rank them by global maxima, to do that I plotted them as:

Plot[x1 // Values, {x, 0, 1}, PlotLabels -> Placed[Automatic, Above]]

I used PlotLabels to manually see which curve is higher but then I get: enter image description here

Seemingly I have to use Placed[{"...","..."}, Above] to have the labels correctly but I wonder if this can be automated using the association?

Also is there a way to ranked the polynomials in x1 between {x,0,1} without plotting them? I know one can use NMaximize[x1] but how does one specify x between 0 and 1.

$\endgroup$
  • $\begingroup$ Plot[Evaluate[x1 // Values], {x, 0, 1}, PlotLabels -> Placed[Automatic, Above]] or Plot[Evaluate[x1 // Values], {x, 0, 1}, PlotLabels -> Placed[Keys[x1], Above]]? $\endgroup$ – kglr Jan 15 at 13:24
  • $\begingroup$ That would put the polynomials as label instead of the corresponding Keys. $\endgroup$ – William Jan 15 at 13:26
  • $\begingroup$ Oh the latter works :) Thank you $\endgroup$ – William Jan 15 at 13:27
  • $\begingroup$ Is there a way to rank the polynomials based on their maxvalue between 0 and 1? $\endgroup$ – William Jan 15 at 13:31
  • $\begingroup$ I used Table[FindMaxValue[x1[[i]], {x, 0.000001, 1}], {i, Length[xx1]}] // Quiet but how can I keep the association? $\endgroup$ – William Jan 15 at 13:33
4
$\begingroup$
SortBy[x1, - N @ ToRadicals @ MaxValue[{Rationalize @ #, 0 <= x <= 1}, x] &]

<|"pol2" -> (353.073 x + 1154.93 x^2 + 2345.48 x^3 + 3829.64 x^4)/( 354 x + 1143 x^2 + 2320 x^3 + 3811 x^4), "pol1" -> (354.07 x + 1139.01 x^2 + 2301.83 x^3 + 3772.24 x^4)/( 354 x + 1143 x^2 + 2320 x^3 + 3811 x^4)|>

Plot[Evaluate[x1 // Values], {x, 0, 1}, PlotLabels -> Placed[Keys[x1], Above]]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks @kglr but the sorting should show pol2 and then pol1, to correspond correctly to plots. is there anything missing there? $\endgroup$ – William Jan 15 at 13:46
  • 1
    $\begingroup$ @William, fixed now. $\endgroup$ – kglr Jan 15 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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