Qurak

Numerical nonlinear global optimization examples finding multiple optima method 2

Tutorial 3 Schritte, der Reihe nach in einer Sitzung ausgeführt. Jeder Schritt wurde gegen die Engine ausgeführt, und die Ausgabe unten ist, was er erzeugte.

Schritt 1
Clear[f, pts, dots, cplot];
f[x_, y_] := (x^2 + y^2 - 16)^2;
Plot3D[f[x, y], {x, -5, 5}, {y, -5, 5}]
Ausgabe
-Graphics3D-
Schritt 2
{sol, pts} = Reap[
	NMinimize[f[x, y], {{x, -5, 5}, {y, -5, 5}}, Method -> "DifferentialEvolution", EvaluationMonitor :> Sow[{x, y}, "VisitedPoint"]],
	"VisitedPoint"];
sol
Ausgabe
NMinimize[(-16 + x^2 + y^2)^2, {{x, -5, 5}, {y, -5, 5}}, Method -> DifferentialEvolution, EvaluationMonitor :> Sow[{x, y}, VisitedPoint]]
Schritt 3
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]
Ausgabe
-Graphics-

Verwendete Funktionen

Verwandte Rezepte

Alle Rezepte · Funktionsreferenz · Dies aus einem MCP-Client verwenden