0
$\begingroup$

I need to find the values of x, y that correspond to the minimum value of the function (in this example it is -1.0, the black area). Code example:

DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}, 
ColorFunction -> "SunsetColors", PlotLegends -> Automatic]

enter image description here

$\endgroup$
  • 2
    $\begingroup$ It's not very clear if you have the functions and you want to find the minimum, or if you only have an image, and you want to find the minimum from the image. $\endgroup$ – Fraccalo Aug 20 '18 at 12:05
1
$\begingroup$
FindMinimum[Sin[x] Sin[y], {{x, #[[1]]}, {y, #[[2]]}}] & /@ {{-2, 
   2}, {2, -2}}

(* {{-1., {x -> -1.5708, y -> 1.5708}}, {-1., {x -> 1.5708, 
   y -> -1.5708}}} *)

Or for exact results,

Minimize[{Sin[x] Sin[y], 0 <= x <= 4, -3 <= y <= 3}, {x, y}]

(* {-1, {x -> π/2, y -> -(π/2)}} *)

Minimize[{Sin[x] Sin[y], -4 <= x <= 0, -3 <= y <= 3}, {x, y}]

(* {-1, {x -> -(π/2), y -> π/2}} *)
$\endgroup$
1
$\begingroup$
eq = Sin[x] Sin[y];
deq = Grad[eq, {x, y}];
roots = {x, y} /. NSolve[{deq == 0, -4 <= x <= 4, -3 <= y <= 3}, {x, y}]
{{0, 0}, {-3.14159, 0}, {-1.5708, -1.5708}, {-1.5708, 
  1.5708}, {1.5708, -1.5708}, {1.5708, 1.5708}, {3.14159, 0}}

hesse[x_, y_] = D[eq, {{x, y}, 2}] /. Thread[{x, y} -> #] & /@ roots;
{PositiveDefiniteMatrixQ /@ hesse[x, y], NegativeDefiniteMatrixQ /@ hesse[x, y]} // Column
{False, False, False, True, True, False, False},
{False, False, True, False, False, True, False}

 eq /. Thread[{x, y} -> #] & /@ roots
{0, 0., 1., -1., -1., 1., 0.}

The 4th and 5th zeros are the searched minima.

$\endgroup$

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.