(* finding local minima for a function of two variables *) (* To run on command line: math -run "<False] Plot3D[F[x, y], {x, a, b}, {y, a, b}] answer = NMinimize[F[x, y], {x,y}, AccuracyGoal -> 2, Method -> {"RandomSearch", Method -> "Gradient", "SearchPoints" -> Nstrt}] xmin = x /. answer[ [2] ] ymin = y /. answer[ [2] ] Fmin = answer[ [1] ] pts = Reap[ NMinimize[F[x, y], {x, y}, AccuracyGoal -> 2, Method -> {"RandomSearch", Method -> "Gradient", "SearchPoints" -> Nstrt}, StepMonitor :> Sow[{x, y}]]][[2, 1]]; pts = Join[{{-1.2, 1}}, pts]; ContourPlot[F[x, y], {x, -2, 2}, {y, -3, 3}, Epilog -> {Arrow[pts], Point[pts]}, Contours -> 10, ColorFunction -> (Hue[.6 (1 - #1)] &), ColorFunctionScaling -> False] Print[" "] Print["Values of x,y that minimizes F, (xmin, ymin) = ", xmin, " ", ymin] Print[" "] Print[" F(xmin, ymin)= ", Fmin] Print[" "]