# To show optimization movement when using FindMinimum [closed]

The code is suppose to show the movement of optimization points from the first until the minimum point is found on the Contour Plot. However, the plot that I have is not showing the correct movement as expected in the example.

f = Reap[FindMinimum[{(-10 x)/((x - 1)^2 + (y - 1)^2 + 1) -
2000/((x + 1)^2 + (y + 1)^2 + 1),
x^2 + y^2 > 2}, {{x, 1.5}, {y, 0}},
StepMonitor -> (Sow[{x, y}])];];
ContourPlot[-(100/((x - 1)^2 + (y - 1)^2 + 1)) -
200/((x + 1)^2 + (y + 2)^2 + 1), {x, -3, 3}, {y, -4, 2},
RegionFunction -> (#1^2 + #2^2 > 2 &), Contours -> 10,
Epilog -> {Red, Text["Constrained Area", {0, 0}], Line[f[]],
Yellow, Map[Point, f[]], Blue, PointSize[0.02],
Point[f[[2, 1, 1]]]}, ContourLabels -> True]


However I can't reproduce the lines and points showing the movement of optimization process with an error message saying:

Coordinate {$CellContextx,$CellContexty} should be a pair of numbers, or a Scaled or Offset form.


What I should get: Help is much appreciated.

Edit2:

I have corrected again my code as below ad produced the following chart. The error message is gone:

f = Reap[FindMinimum[{-((10 x)/((x - 1)^2 + (y - 1)^2 + 1)) -
2000/((x + 1)^2 + (y + 2)^2 + 1),
x^2 + y^2 > 2}, {{x, 1.5}, {y, 0}},
StepMonitor :> (Sow[{x, y}])];];
ContourPlot[-(100/((x - 1)^2 + (y - 1)^2 + 1)) -
200/((x + 1)^2 + (y + 2)^2 + 1), {x, -3, 3}, {y, -4, 2},
RegionFunction -> (#1^2 + #2^2 > 2 &), Contours -> 10,
Epilog -> ({Red, Text["Constrained Area", {0, 0}], Line[f[]],
Yellow, Map[Point, f[]], Blue, PointSize[0.02],
Point[f[[2, 1, 1]]]}), ContourLabels -> True] • Extremely important: Change StepMonitor -> (Sow[{x, y}]) to StepMonitor :> (Sow[{x, y}]). Then it will work (although it doesn't seem to be finding the minimum). – march Mar 26 '16 at 4:51
• Oh: the reason why it's not finding the right minimum is because the function you are finding the mimimum of is not the one that you're plotting. Make sure they're the same and things will work better. – march Mar 26 '16 at 4:57
• That's weird, I copied exactly the same code (accept for the StepMonitor mistake as you mentioned). But somehow obtained different result – iFikr Mar 26 '16 at 5:02
• I have reworded the question to be more useful and hopefully beneficial for future visitors – iFikr Mar 26 '16 at 11:31
• @iFikr Actually I looked at the youtube video you linked: the author of that video also made the same mistake of not plotting the function he had minimized, probably due to typos in copying the numerical factors. You might want to change that in your edit. – MarcoB Mar 26 '16 at 13:03