# ContourPlot - plot contour lines for minimum of list of functions == 2nd minimum of list of functions

I have a list of (ten or so) functions of two variables (x and y, say). I would like to plot the boundaries on the x y plane where two functions have the same value - but only the two functions in the list which have the smallest values at that particular point. Can this be done? (The Physics application - I have a number of states with different energies (the list of functions), and I am trying to plot the different regions where different states are the ground state.)

Edit follows,

Thanks for your help. I have made some progress with this - functions are parabola. Here is my code so far.

Clear[a, x, y, m, n, p, l]
m[x_, y_] := x^2 + y^2;
n[x_, y_] := x^2 + (2 y + 1)^2;
p[x_, y_] := (x + 1)^2 + y^2;
l = {m[x, y], n[x, y], p[x, y]};
ContourPlot[l[[First[Ordering[l, 2]]]] == l[[Last[Ordering[l, 2]]]], {x,-4,4}, {y,-4,4}, PlotPoints -> 200]
RegionPlot[l[[Last[Ordering[l, 2]]]]-l[[First[Ordering[l, 2]]]]<0.05,{x,-4,4},{y, -4, 4},PlotPoints->200]


The ContourPlot does not work - I get a blank plot - but the RegionPlot does show the regions where the lowest two functions are approximately equal. So is this something to do with the precision at which the calculation is carried out?

I did try the solution provided by Verde - thankyou very much for that - but I didn't fully understand it, and had trouble integrating it with the rest of my code.

Any further help would be much appreciated!

Nick

-
Could you give some basic examples of functions and study cases? This would be helpful if given in Mathematica code. –  Vitaliy Kaurov Aug 8 '12 at 19:28
Sound possible. But it might be helpful for others to be sure what exactly you want if you give an example. And welcome to Mathematica.SE! –  Silvia Aug 8 '12 at 19:34
See edit above! –  Nick Lambert Aug 9 '12 at 15:07

RankedMin may be convenient in this context:

ClearAll[m, n, p, diftwomins];
m[x_, y_] := x^2 + y^2;
n[x_, y_] := x^2 + (2 y + 1)^2;
p[x_, y_] := (x + 1)^2 + y^2;
diftwomins[x_, y_] := (RankedMin[#, 2]-RankedMin[#, 1]) &@(#[x, y] & /@ {m, n, p});
GraphicsRow[{Plot3D[diftwomins[x, y], {x, -4, 4}, {y, -4, 4},
BoxRatios -> 1, PlotPoints -> 100, ImageSize -> 300],
ContourPlot[diftwomins[x, y], {x, -4, 4}, {y, -4, 4},
PlotPoints -> 200, ImageSize -> 300]}]


-

Here's one way using ContourPlot:

Clear[a, x, y, m, n, p, l]
m[x_, y_] := x^2 + y^2;
n[x_, y_] := x^2 + (2 y + 1)^2;
p[x_, y_] := (x + 1)^2 + y^2;
l = {m[x, y], n[x, y], p[x, y]};
ContourPlot[
Evaluate[Table[l[[i]] - Min[Delete[l, i]] == 0, {i, Length[l]}]],
{x, -2, 2}, {y, -2, 2}, Exclusions -> None]


-
Wonderful - very elegant! Thank you very much indeed. –  Nick Lambert Aug 9 '12 at 16:01
l = {Sin[#], Sin[#] UnitBox[Norm@{#} ], 3, Sin[ Norm@#]} &;
b[l_] := Count[Chop[Min[l[x y]] - l[x y]], 0] >= 2.
RegionPlot[b[l], {x, -3, 3}, {y, -3, 3}, PlotPoints -> 100]


-