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.
The code as per example from this youtube video: https://www.youtube.com/watch?v=vXzfnExR_t4
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[[2]]],
Yellow, Map[Point, f[[2]]], 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 {$CellContext`x, $CellContext`y} should be a pair of numbers, or a Scaled or Offset form.
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[[2]]],
Yellow, Map[Point, f[[2]]], Blue, PointSize[0.02],
Point[f[[2, 1, 1]]]}), ContourLabels -> True]
StepMonitor -> (Sow[{x, y}])
toStepMonitor :> (Sow[{x, y}])
. Then it will work (although it doesn't seem to be finding the minimum). $\endgroup$