درس 3 خطوات تُشغَّل بالترتيب في جلسة واحدة. كل خطوة نُفِّذت على المحرك والمخرج أدناه هو ما أنتجته.
Clear[f, pts, dots, cplot];
f[x_, y_] := (x^2 + y^2 - 16)^2;
Plot3D[f[x, y], {x, -5, 5}, {y, -5, 5}]-Graphics3D-{sol, pts} = Reap[
NMinimize[f[x, y], {{x, -5, 5}, {y, -5, 5}}, Method -> "DifferentialEvolution", EvaluationMonitor :> Sow[{x, y}, "VisitedPoint"]],
"VisitedPoint"];
solNMinimize[(-16 + x^2 + y^2)^2, {{x, -5, 5}, {y, -5, 5}}, Method -> DifferentialEvolution, EvaluationMonitor :> Sow[{x, y}, VisitedPoint]]newpts = Cases[First[pts], x_ /; Abs[f@@x - First[sol]] ≤ .05];
rainbow[a_] := Hue[0.75 a, .5, 1];
dots = Graphics[Join[{PointSize[0.02], RGBColor[1, 1, 1], Point[#]& /@ newpts}, {{PointSize[0.02], RGBColor[0, 0, 0], Point[{x, y} /. Last[sol]]}}]];
cplot = ContourPlot[f[x, y], {x, -5, 5}, {y, -5, 5}, ColorFunction -> rainbow, Contours -> 4Range[0, 10] ^ 2, PlotPoints -> 50];
Show[cplot, dots]-Graphics-