1
$\begingroup$

Hello i am trying to compare many function, i want to see witch one as the lowest value depending on 2 variables.

My solution so far is something like this:

I have 7 function: P1 P2 P3 P4 P5 P6 P7, variable are v and d:

RegionPlot[{ P1 [d, V, A] <= P2[d, V, A] && P1 [d, V, A] <= P3[d, V, A] && P1 [d, V, A] <= P4[d, V, A] && P1 [d, V, A] <= P5[d, V, A] && P1 [d, V, A] <= P6[d, V, A] && P1 [d, V, A] <= P7[d, V, A] , P2[d, V, A] < P1[d, V, A] && P2[d, V, A] <= P3[d, V, A] && P2[d, V, A] <= P4[d, V, A] && P2[d, V, A] <= P5[d, V, A] && P2[d, V, A] <= P6[d, V, A] && P2[d, V, A] <= P7[d, V, A], P3[d, V, A] < P1[d, V, A] && P3[d, V, A] <= P2[d, V, A] && P3[d, V, A] <= P4[d, V, A] && P3[d, V, A] <= P5[d, V, A] && P3[d, V, A] <= P6[d, V, A] && P3[d, V, A] <= P7[d, V, A], P4[d, V, A] < P1[d, V, A] && P4[d, V, A] <= P2[d, V, A] && P4[d, V, A] <= P3[d, V, A] && P4[d, V, A] <= P5[d, V, A] && P4[d, V, A] <= P6[d, V, A] && P4[d, V, A] <= P7[d, V, A], P5[d, V, A] < P1[d, V, A] && P5[d, V, A] <= P2[d, V, A] && P5[d, V, A] <= P3[d, V, A] && P5[d, V, A] <= P4[d, V, A] && P5[d, V, A] <= P6[d, V, A] && P5[d, V, A] <= P7[d, V, A], P6[d, V, A] < P1[d, V, A] && P6[d, V, A] <= P2[d, V, A] && P6[d, V, A] <= P3[d, V, A] && P6[d, V, A] <= P4[d, V, A] && P6[d, V, A] <= P5[d, V, A] && P6[d, V, A] <= P7[d, V, A], P7[d, V, A] < P1[d, V, A] && P7[d, V, A] <= P2[d, V, A] && P7[d, V, A] <= P3[d, V, A] && P7[d, V, A] <= P4[d, V, A] && P7[d, V, A] <= P5[d, V, A] && P7[d, V, A] < P6[d, V, A]}, {d, 0, 2}, {V, -0.1, 0.3}, PlotStyle -> {Directive[Red], Directive[Blue], Directive[Orange], Directive[Yellow], Directive[Purple], Directive[Green], Directive[Black]}, PerformanceGoal -> "Speed", PlotPoints -> 20] 

and i might want to compare more thna 7 function... is there a fast way to do it

thanks

$\endgroup$
2
  • $\begingroup$ Although no one's posted Michael E2's Ordering-based solution at the previous question. $\endgroup$ Commented Aug 26, 2014 at 17:49
  • $\begingroup$ @RahulNarain My memory must be bad. It wasn't even that long ago that I answered that Q. I've added this method to my answer, in case this one is closed. $\endgroup$ Commented Aug 26, 2014 at 19:00

2 Answers 2

6
$\begingroup$

Here's a different approach to consider. Ordering[fns, 1] returns the index of the function whose value is least for given numeric values for x adn y. (Should there be a tie, it will return the first index only). We can use this in ContourPlot to plot the regions.

fns = {x + y, 2 x - y, 1 - x^2 - y^2, (x - 1)^2 + (y - 1)^2 - 2, 2 Sin[x y] - 1/2}; ContourPlot[Ordering[fns, 1], {x, -2, 2}, {y, -2, 2}, Contours -> 1/2 + Range[Length@fns - 1], MaxRecursion -> 3] 

Mathematica graphics

$\endgroup$
2
$\begingroup$

With a list of your functions

functions = {P1[d, V, A], P2[d, V, A], P3[d, V, A], P4[d, V, A], P5[d, V, A], P6[d, V, A]}; 

you can create a list of all combinations using

And @@ # & /@ MapIndexed[Drop, Partition[#[[1]] < #[[2]] & /@ Tuples[functions, 2], Length @ functions]] 
$\endgroup$
1
  • 1
    $\begingroup$ I have mixed feelings about compact notation such as And @@ # & /@ , so powerful on the on hand, but on the other hand so hard to parse for new users. $\endgroup$ Commented Aug 26, 2014 at 16:16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.