(* finding local minima for a function of one variable *) (* Value of option Method is either "Automatic", "Gradient", "ConjugateGradient", "QuasiNewton", "Newton", or "LevenbergMarquardt". *) F[x_, y_] := x^2 + y^2; (* simplest possible *) (* F[x_, y_] := x^20 + y^20; (* ill-conditioned. Too shallow *) *) (* F[x_, y_] := 100(y - x^2)^2 + (1-x)^2; *) (* Steepest descent (Gradient) fails *) (* Need ConjugateGradient or Newton *) ContourPlot[F[x, y], {x, -1, 1}, {y, -1, 1}, ContourShading->False] Plot3D[F[x, y], {x, -1, 1}, {y, -1, 1}] answer = FindMinimum [F[x, y], {x, .5}, {y, .5}, PrecisionGoal -> 0.1, MaxIterations -> 50, Method->Newton] xmin = x /. answer[ [2] ] ymin = y /. answer[ [2] ] Fmin = answer[ [1] ] Print[" "] Print["Values of x,y that minimizes F, (xmin, ymin) = ", xmin, " ", ymin] Print[" "] Print[" F(xmin, ymin)= ", Fmin] Print[" "]