Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Let's take this example:

DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}]

How do I retrieve the minimum value and position of the minimum of a plot from the plot? How do I tell Mathematica to mark the position of the minimum/minima within the plot?

And for ContourPlots

ContourPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}]

Is there a way to mark the exact minimum position within the plot even though it's a contour plot?

Yes, Jens and Szabolcs, that would be the best way if i could manage to write the code for that. I'm still a beginner with mathematica and haven't managed so far to cope with that problem because....well i think i have to post a piece of my code to show it. I have deleted most of the variables and replaced them by constants for simplicity reasons:

eislexpl[epsilon_, n2_, x_] :=  28 (epsilon)^2 - 1 + 
((-2 Log[E^(1/2) x])/x^2 + (2.7(0.3 - epsilon))/x + 
(10 epsilon^2 n2^(3/2))/x^(3/2));

eislminx2[epsilon_?NumericQ, n2_?NumericQ] := 
(minx = FindArgMin[{eislexpl[epsilon, n2, x], 0 < x}, x];
eislexpl[epsilon, n2, minx]);

ueislexpl[epsilon_, h_, n1_, n2_] := 
n1 (40  epsilon^2 - 1) + (1 -1.27 ) (1 + (n1 - 1) HeavisideTheta[1 - n1] - 
(-1 + Exp[-(n1 - 1)]) HeavisideTheta[n1 - 1]) + n2  eislminx2[epsilon, n2] + 
(h - n1 - n2) (28  epsilon^2 - 1);

ueislexpl[epsilon_, h_, n1_, n2_] is the function i need to find the minimum for. But the problem for me is, that it calls this function eislminx[epsilon_?NumericQ,n2_?NumericQ]. So my problem is that in order to have a function that mathematica is able to find a minimum for, i have to plug n2 in eislminx[epsilon_?NumericQ,n2_?NumericQ], so that this part of ueislexpl[epsilon_, h_, n1_, n2_] determined, but at the same time i want to find the minimum for ueislexpl[epsilon_, h_, n1_, n2_] with respect to n2. So if anybody know how to find the minimum of ueislexpl[epsilon_, h_, n1_, n2_] with respect to n2 and n1 i would be happy to learn how.

Thanks for the help.

Well, my actual question has been answered by kguler, thanks again ;) And the question of how to find the minimum of that function above i will source out to here: FindMinimum of function

share|improve this question
    
Look up FindMinimum, Minimize, and Epilog. –  Jens Aug 8 at 18:33
    
As Jens suggests, first find the minimum of the function, and then add it to the plot. –  Szabolcs Aug 8 at 18:34
    
Dealing with multiple global minima is likely going to be difficult. Do you really need this, or would you be satisfied with a single minimum? Are you working with analytical functions or numerical blackboxes? –  Szabolcs Aug 8 at 18:37
    
@Szabolcs, do you thin this can be done be extracting info from FullForm of the plot? –  Algohi Aug 8 at 18:42
    
@Algohi I'm sure it can be done, but why would anyone go to all that trouble if they already have the function available? Also, it's probably not going to be very precise when done that way, so it's much simpler to just find it "by eye" (assuming that only the plot is available and the function used to make the plot was lost). –  Szabolcs Aug 8 at 19:08

2 Answers 2

up vote 6 down vote accepted

A quick-and-dirty way: get the contours for the .0000001st and .9999999th quantiles as approximations for min and max

dp = DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}];
cp1 = ContourPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}, 
            ContourShading -> None, 
            ContourStyle -> {Directive[Red, Thick], Directive[Orange, Thick]}, 
            Contours -> Function[{min, max}, 
                          Rescale[{.00000001, .99999999999}, {0, 1}, {min, max}]]];
cp2 = ContourPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3},  ContourShading -> None];
Legended[Show[dp, cp1, cp2], 
             PointLegend[{Red, Orange}, {"min", "max"}, LabelStyle -> 16, 
                         BaseStyle -> PointSize[Large]]]

enter image description here

share|improve this answer
    
Thanks again for your help, kguler, that works just fine :) –  11drsnuggles11 Aug 9 at 5:55
min = Minimize[
   {Sin[x] Sin[y], -4 < x < 4, -3 < y < 3},
   {x, y}][[1]]

-1

minPts = Cases[
  Reduce[{Sin[x] Sin[y] == min, -4 < x < 4, -3 < y < 3}, {x, 
    y}], (x == x1_ && y == y1_) :> {x1, y1}, Infinity]

{{-(Pi/2), Pi/2}, {Pi/2, -(Pi/2)}}

DensityPlot[
 Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3},
 Epilog ->
  {Red, AbsolutePointSize[6], Point[minPts]}]

enter image description here

ContourPlot[
 Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3},
 Epilog ->
  {Red, AbsolutePointSize[6], Point[minPts]}]

enter image description here

share|improve this answer
    
you could also use ArgMin[{Sin[x] Sin[y], -4 < x < 4, -3 < y < 3}, {x, y}] –  chris Aug 9 at 13:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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